While working as a Salesforce Administrator, I was assigned the task of assigning an urgency rating to cases based on the case source’s first character.
So, as a solution, I found that Salesforce provides a function named BEGINS, which helped me assign ratings to cases based on the case source’s first character.
In this tutorial, we will learn how to use the BEGINS function in Salesforce to determine whether text begins with specific characters. We will also understand its syntax and a few real-world business-related useful examples.
What is the BEGINS() Function in Salesforce
The BEGINS() function is one of the Salesforce text functions used to perform text operations. In general, the BEGINS() function checks whether text begins with the specified characters; it returns TRUE if it does and FALSE otherwise.
Make sure of the following points while working on the BEGINS function:
- The BEGIN function is case-sensitive, so it treats the compare text differently for both lowercase and uppercase.
- Fields that are left blank when utilising this function in a workflow rule or validation rule are treated as valid. For instance, if a validation rule checks to see if an order starts with “56” all records with the blank order id number are accepted as valid.
Syntax and Usage of the BEGINS() Function in Salesforce
Below is the syntax of the BEGINS function in Salesforce:
BEGINS(text, compare_text)Here:
- Text: It specifies the value or field that you want to check. It can be anything: a single plain string, text, or a reference to the text field.
- compare_text: It specifies the value of the prefix that we want to look at the beginning of the text value. It can be plain text enclosed in double or single quotes, a numerical value, or a field that has a compared value.
Let’s look at scenarios to understand the BEGINS function better.
As I discussed, I was assigned the task of assigning an urgency rating to cases based on the case source’s first character. So, here is the function-based formula with the use of the BEGIN function.
IF(
OR(
BEGINS(Case_Source, "Phone"),
BEGINS(Case_Source, "Email"),
BEGINS(Case_Source, "Lead")
),
10,
5
)With this, we have learned the syntax of the BEGINS() function with a real-life-based scenario. Now, we will proceed to learn how to use the BEGINS() function in a Salesforce Lightning Component.
Use the BEGINS() Function in Salesforce
The following steps show how to use the BEGINS() function in Salesforce.
- Go to the “Gear Icon”. Then click the “Setup“.

- The setup page opens when you select the Setup option. Here, the “Object Manager” is found in the Navigation Bar next to the Home tab. Click on it.

- The object manager page opens when you click it. There are numerous objects seen here. Use the Quick Find Search field to look for the item on which we want to use the BEGINS() function.
- In this instance, I look for the “Coupon” object because I need to convert the product price to text and also concatenate the USD text to it.
- Now, click the “Coupon” object to move to the product object page.

- Select “Field & Relationship“ from the menu.
- The field and relationships page opens when it is selected. Click the “New” button at the top of the page.

- The field type page opens when you click the new button. The page contains multiple field types. In this case, I chose the “Formula“ field type, as I want to use the BEGINS function in the advanced formula.
- Click the “Next” button to move on to the next step.

- The choose output type screen appears when you click the following button. Enter the information now by filling out the “Field Label” and the “Field Name”, which is automatically filled out. In this instance, I entered the “Prize” into the field label.
- Choose the “Output Data Type“ for the field in which we want to store the result. In this case, I check the “Text” data type radio button to return the formula result as text.
- Move to the next step by clicking the “Next” button.

- Go to the advanced formula editor, move to the right side of the page in the Functions Section, and choose the Text Categories Function from the dropdown.
- Now, select the BEGINS from here and enter the BEGINS() function formula there. In this instance, I want to use the BEGINS function to declare the first price based on the coupon code. The formula is as follows:
IF(
BEGINS(CouponCode, 'FR5968DS'),
'Won IPhone13',
'Better Luck Next Time'
)- We use the BEGINS() function to check whether the CouponCode begins with the specific character “FR5968DS”.
- Then we use the IF() function to print the prize message based on the result of the BEGINS() function.
- If the CouponCode begins with the specified characters, it prints the message “Won iPhone 13”.
- If the CouponCode does not begin with the specified characters, it prints the message Better Luck Next Time.
- To check the formula and make sure there are no errors, click the “Check Syntax” option.
- Optionally, we can define the “Description,” “Help text,” and “Handle the empty field” if you want.
- Click the “Next” button to go to the security setup for the formula field that uses the BEGINS function.

- In this step, establish “Field-Level Security“. Choose the user profiles to which we wish to grant field-level security edit access to this field. If field-level security is not added, this custom formula field will not be shown on all profiles.
- As I want it to be visible to all profiles, I have checked the “Visible” checkbox.
- After that, click the “Next” button located at the top.

- Add the custom formula field we created to the “Page Layout“ after setting up field-level security. Now, select the page layout that contains this field. If we do not choose a layout, the field will not appear on any pages.
- To save the formula field, click the “Save” button.

We can use the formula field once we have created it. Let’s look at an example:
- Open the Coupon Tab and create a new coupon with the field Coupon Name.
- The Prize field, which displays the output of the BEGINS() function, will be shown in the Details Section.
As a result, we now understand how to use the BEGINS function in Salesforce.
Conclusion
In conclusion, we have learned the Salesforce BEGINS() function. Moreover, we have learned the syntax of the BEGINS() function in Salesforce and several real-world business scenarios.
In addition, we also covered the steps for using the BEGINS() Function in the Salesforce component.
You may like to read:
- ASCII() Function in Salesforce
- TEXT() Function in Salesforce
- TRUNC() Function in Salesforce
- ATAN2() Function in Salesforce
I am Bijay Kumar, the founder of SalesforceFAQs.com. Having over 10 years of experience working in salesforce technologies for clients across the world (Canada, Australia, United States, United Kingdom, New Zealand, etc.). I am a certified salesforce administrator and expert with experience in developing salesforce applications and projects. My goal is to make it easy for people to learn and use salesforce technologies by providing simple and easy-to-understand solutions. Check out the complete profile on About us.