What’s trending
UPCOMING EVENTS
50+ Salesforce Formulas to Supercharge Your Productivity
By Andreea Doroftei
When it comes to formulas, which are used extensively in Salesforce, the first thing that comes to mind is a good old formula field! During this guide, we will dive into a variety of Salesforce formula examples, as well as the common scenarios in which formulas (used in different locations) can make your life as a Salesforce Admin much easier.
If you haven’t yet created your first formula field yet, feel free to take a look at our interactive tutorial post – learning how to get started may be useful before exploring the examples below.
Formula Fields 101
Before going through some examples, it’s worth noting a few key considerations:
- Formula fields are not editable. If the value displayed is not correct, the formula has to be changed so that the desired outcome will show up on records.
- A formula field can be used for a range of calculations between fields and for displaying data from related Object records, as well as displaying pictures.
- After building a formula field, it is automatically populated for historical records as well.
- Formula field changes cannot trigger automations.
You can check out all the current limitations and restrictions for formula fields here.
Salesforce Formula Examples
We’ve split the examples into several categories based on where they’re being used to cover a few more use cases. You can also categorize them in other ways, depending on your preference.
Before starting to build your formulas, make sure you are familiar with at least the main operators and formula functions:
- Math Operators
- Logical Operators
- Text Operators
- Date and Time Functions
- Logical Functions
- Math Functions
- Text Functions
- Summary Functions
- Advanced Functions
Field-Level Formulas
From the most simple to some of the most complex examples, formula fields are calculated after the record is saved and can include a wide variety of functions, operators, and fields from the object at hand or related objects.
Calculate Basic Commission on Opportunities
IF(Amount < 10000, Amount * 0.10, Amount * 0.15)
The commission is calculated based on the Opportunity Amount. If the Opportunity Amount is less than 10K, the commission is 10%; otherwise, it is 15%. This calculation is performed by a simple IF statement, and the resulting commission is displayed.
Calculate a Lead Score
(IF( AnnualRevenue = 0, 0, 10)) + (IF(ISPICKVAL(Industry, “”) , 0, 10)) + (IF( MobilePhone = “”, 0, 10))
A basic Lead score formula looks at whether fields are blank or not (and assigns them a score if not). We can then add these together. Please note that the ISPICKVAL
function is necessary if you are using a picklist field.
Calculate an Account’s Region
Here’s a great example of a formula field assigning West, Central, East, South, North, or Other based on the state. This was taken from the Salesforce help page.
IF(ISBLANK(BillingState), “None”, IF(CONTAINS(“AK:AZ:CA:HA:NV:NM:OR:UT:WA”,
BillingState), “West”, IF(CONTAINS(“CO:ID:MT:KS:OK:TX:WY”, BillingState), “Central”,
IF(CONTAINS(“CT:ME:MA:NH:NY:PA:RI:VT”, BillingState), “East”,
IF(CONTAINS(“AL:AR:DC:DE:FL:GA:KY:LA:MD:MS:NC:NJ:SC:TN:VA:WV”, BillingState),
“South”, IF(CONTAINS(“IL:IN:IA:MI:MN:MO:NE:ND:OH:SD:WI”, BillingState), “North”,
“Other”))))))
Using Images in Formula Fields
One of the best things about Formula Fields is the ability to display images as an output. So, in the example above with the Lead Score, we could output an image to display how “Hot” the lead is instead of outputting a number..
Salesforce has a bunch of images that can be used straight out of the box. You can grab a whole list of them here (you will need to remove some of the URLs, as instructed). There is also an AppExchange pack you can install to get hold of some more.
Continuing the example with Lead score, let’s create a formula with images.
CASE(Lead_Score__c ,
10 , IMAGE(“/img/samples/light_red.gif”, “light”),
20,IMAGE(“/img/samples/light_yellow.gif”, “light”) ,
30 ,IMAGE(“/img/samples/light_green.gif”, “light”), “”)
Using a CASE
statement (similar to an IF
statement but it can have more outcomes), we can look at our Lead Score field and assign an Image URL using the IMAGE
function. If the score is 10, assign a red traffic light. If the score is 20, assign a yellow light, and if 30, assign the green. Easy!
Record Owner Category
This is a formula that, once again, can be used in validation rules, automations, reports – you name it! It can be built as a formula field or directly within the automation, and it will be handy to know at all times whether the record owner for objects that support queue assignment is a queue or user.
IF(BEGINS(OwnerId, "005","User","Queue"))
OR
IF(BEGINS(OwnerId, "00G","Queue","User"))
OR (if you prefer the formula output to be a checkbox)
IF(BEGINS(OwnerId,"005",1,0)
Information from Parent Account
Fairly often, there might be a request to get and display certain information from the records above in the Account hierarchy on individual records. The below IF()
statement is perfect for a couple of levels higher, but CASE()
can also be used, especially when multiple outcomes are possible.
IF(NOT(ISBLANK(Parent.Parent.Id)),Parent.Parent.AnnualRevenue,IF(NOT(ISBLANK(Parent.Id)),Parent.AnnualRevenue, "")
Check if a Field Value Contains a Certain String
When possible, the ideal scenario is to use exact criteria – be it report filters or formulas – as equals are much more effective and less prone to errors than checking if a string contains a word. Sometimes, however, it does make sense to check instead.
For example, the Type field on the Opportunity in my developer sandbox has four values, three of which contain the word “existing”, basing how the Opportunity priority will be defined.
Note that Type is a picklist field, hence, the function TEXT()
will be used to transform the picklist into text within the formula.
IF(CONTAINS(TEXT(Type),"Existing"),"High", "Medium")
The CONTAINS()
function, however, does not support multi-select picklists. If you wanted to check this, you would have to use INCLUDES()
instead, as well as the value the multi-select field should include. For this, I created a custom multi-select picklist for Type to include more granular values that can be simultaneously selected.
IF(INCLUDES(Type__c,"Existing Customer"), "High","Medium")
Also, since we’re on the topic of multi-select picklists, there is a function that has been released more recently that you should know about – it can be used in a formula and returns the count of how many values are chosen in a multi-select picklist.
PICKLISTCOUNT(Type__c)
Extract Part of a String
There is no need to have a very complicated formula to return characters from the middle of the string and know the exact number of characters you need as the output.
The MID()
function needs the position of the character the part of the string you need starts with first, then the number of characters you need to return, and voila!
MID(Text_Field__c, 3, 5)
Alternatively, if you’re just looking forward to just grabbing the first few or last few characters of a string, there’s always the LEFT()
and RIGHT()
functions to use.
It is also good practice to pair these up with TRIM()
, which removes the spaces and tabs from the beginning and end of the string. With our custom field example, let’s retrieve only the first three characters: TRIM(LEFT(Text_Field__c, 3))
Hyperlink
The transition to Lightning experience means that many of us would simply use a rich text component to display nicely organized hyperlinks at the top of the record page. However, there are still situations where the hyperlink formula is useful, as the lightning component can’t be displayed and accessed in reports or list views.
You could add a hyperlink formula field next to the Opportunity Next Step to provide instructions on how to complete it directly on the detail page (in both Lightning and Classic). Also, you can add a couple of links in as well – why not?
Tip: Make sure you use the shortest URL possible.
HYPERLINK("www.google.com", "How to complete all relevant Next Steps") & BR() & HYPERLINK("www.google.com", "How to Close Deals faster")

Number of Days Between Two Dates
The simplest date formula in Salesforce is to calculate the number of days between two dates. This can then be used in reports – perhaps as part of automation criteria – or to set deadlines for records to be actioned, offering users additional visibility.
To find the number of days since a record was created, simply subtract the CreatedDate from TODAY()
.
TODAY() - DATEVALUE(CreatedDate)
Find Out the Day of the Week
The first formula that comes to my mind when thinking about date fields is the one that helps us find out the day of the week.
For example, you can easily provide insight and analyze which days of the week are the most productive to help close Opportunities.
CASE(WEEKDAY(CloseDate),
1, "Sunday",
2, "Monday",
3, "Tuesday",
4, "Wednesday",
5, "Thursday",
6, "Friday",
7, "Saturday",
"N/A")
More Examples:
- NOW(): How to Send Birthday Campaigns with Account Engagement (Pardot)
- TODAY() Salesforce for Fundraising: A Complete Guide
Object-Specific
Looking at Objects in particular? These articles should be your next stop:
- Salesforce Admins Best Practice: Top 6 Fields on the Contact Object
- 5 Formula Fields to Add to Your Salesforce Campaign KPIs
Account Engagement-Specific
We have plenty of resources available when it comes toMarketing Cloud Account Engagement (Pardot), including some interactive tutorials:
- Guide: Salesforce Star Rating Formula Fields for Prospect Score
- Open the Pardot URL in the Pardot Lighting App [Interactive Tutorial]
- Pardot Scoring vs Grading: Pinpoint Hot Prospects
You may also be interested in the following articles:
- How to Use the Salesforce VLOOKUP Function
- Use Images in Salesforce Formula Fields
- Best Practices for Formatting & Fixing Formulas in Salesforce + VIDEO
Formulas Within Salesforce Reports
While most of us are already familiar with IF() row-level formulas in a Salesforce report, or a very simple average, it might slip our minds how much easier it is to create a report formula (rather than formula fields).
Row-Level Formula
A very easy one to use is row-level formulas, which allow you to define a value of the formula for each of the records in the report.
For example, instead of creating a formula field to calculate the number of days between two date fields, you can do so in a report.
The report below only shows Accounts with one Closed Won Opportunity. I wanted to see how many days had passed between the Account being created and the Opportunity being closed. In my use case, whenever an Account is created, an Opportunity should be created as well.
CLOSE_DATE - DATEVALUE(ACCOUNT_CREATED_DATE)

Complex Report Formulas
In Salesforce reports, there are two formulas that – if understood and used correctly – can enable you to build powerful reports using the standard Salesforce reports only instead of exporting in Excel or potentially using a BI tool from the get-go.
These formulas can be used at grouping levels and are very specific to the calculation you’re looking forward to running in your report. So make sure you read all documentation details, along with the examples.
The one use case of PARENTGROUPVAL()
that I always go back to is the ability to showcase the percentage each grouping level represents out of the total.
This can prove to be really useful when looking forward to seeing a calculated percentage breakdown, for example, of how the Opportunities forecasted to close this FQ are doing.
RowCount / PARENTGROUPVAL(RowCount, GRAND_SUMMARY)

Salesforce Reports Formula Fields
Check out the following articles for support with reports:
- Summary Formulas vs Row Level Formulas in Salesforce [+ Examples]
- Create Eye-catching Salesforce Reports with Conditional Formatting
Validation Rules
Activity Validation
One question I have seen popping up a couple of times recently relates to creating validation rules on Activities. It is possible as long as the validation is created on either the Task or Event object. The below example is on the Task object and is meant to require more details if certain conditions are met:
AND(
ISPICKVAL(Priority,"High"),
ISPICKVAL(Status,"Waiting on someone else"),
ISBLANK(Description))
As an alternative to the logical function AND()
you can use && instead:
ISPICKVAL(Priority,"High") &&
ISPICKVAL(Status,"Waiting on someone else") &&
ISBLANK(Description)
Similarly, if there is a need to use OR()
for a formula or validation rule, ||
can be used instead. Keep in mind that this changes the validation rule entirely, so instead of all conditions having to be met, the validation rule would fire if the Comments field is still blank, but TBD.
(ISPICKVAL(Priority,"High") ||
ISPICKVAL(Status,"Waiting on someone else")) &&
ISBLANK(Description)
For added clarity within the formula, especially when it is more complex or if you would like to temporarily remove part of it but not actually delete it, you can comment. Comments, however, shouldn’t replace the use of the Description and can be used for both validation rules, as we did in this example, or for formula fields.
/ISPICKVAL(Priority,"High") && this is commented for now/
ISPICKVAL(Status,"Waiting on someone else") &&
ISBLANK(Description)
Following the same situation as above, instead of checking if the Comments field is blank, let’s make sure users always input a decent number of characters for the Comments of a High Priority Task.
The LEN()
function returns the count of the number of characters, helping you ensure the minimum level of detail is there.
AND(
ISPICKVAL(Priority,"High"),
ISPICKVAL(Status,"Waiting on someone else"),
LEN(Description) < 30)
Checking the Previous Value of a Field
Especially in validation rules, PRIORVALUE
comes to the rescue when users that normally have permissions to update certain fields shouldn’t anymore.
Common examples vary from editing key Opportunity fields when the Opportunity is closed to updates on converted Leads. This can also prevent admins from making unintentional mistakes on data points that should never undergo changes.
AND(IsClosed,PRIORVALUE(OwnerId) <> OwnerId)
Use Formula Assistant
Given the capabilities of Agentforce, it’s only natural that you can now use generative AI to create formulas, whether you’re working with Formula Fields or Validation Rules. Einstein for Formulas can either spot any errors or offer to explain what the formula does.
Using the example above, including the comment, you’ll see that the assistant confirms the formula is correct and provides an explanation while accounting for the fact that the first part is commented.

More About Validation Rules
You can learn more about how to use validation rules in Salesforce with our step-by-step guide.
Salesforce Flow Formulas
Building formulas directly in the declarative automation tool empowers us to have more control over the automation process.
One of the more recent additions to the family is the ability to use formulas as an entry criteria for the flow instead of individually selecting fields and defining filter logic, as well as other possible scenarios.
Make sure you take a look at the flow formulas considerations before starting this process.
Entry Criteria Formula
There will be situations where you might need more than one of the same type of flow on the same object – this is where the entry criteria come into play.
This ensures that your flow is not triggered by all changes made to the record. The Salesforce recommendation is to always use entry criteria for a flow that should run when records are updated.

The advantage of using this formula is that you can filter by fields on the record and on information from related records.
In this case, the flow I built will create a Task for the Opportunity Owner’s manager whenever the Stage is changed to a specific one and when the Annual Revenue of the Account exceeds a given threshold.
AND(ISPICKVAL({!$Record.StageName},"Proposal/PriceQuote"),
{!$Record.Account.AnnualRevenue} > 500000)
However, depending on your use case, you can also opt to use fields from the triggering record only without having to select each field, operator, and value individually.
AND(ISPICKVAL({!$Record.StageName},"Proposal/PriceQuote"),
{!$Record.Amount} > 70000)
Flow Formula Resources
The formula function I use most often within flows (when creating records) is IF()
. I find that it’s far more efficient than having one Decision element followed by two Create Records elements – one on each branch, depending on the outcome.
In the example below, when a new Opportunity is created, a specific placeholder Close Date is automatically updated depending on the Opportunity Type (which in my org is mandatory at record creation).
IF(ISPICKVAL({!$Record.Type},"New Customer"), TODAY() + 180, TODAY() + 90)

This formula can now be used to set the field value for Close Date, and it will be dynamic based on the value from the Type field.

Use Einstein to Generate Formula Resources
You might have noticed in the screenshot above the sparkles on the side of the editor, as well as the mention of considerations for formulas created by Einstein. The option to use generative AI to create Flow Formulas is generally available in Spring ‘25, which means Einstein can build formulas on your behalf using natural language instructions.
If you opt to use this feature, always check the syntax and thoroughly test the output to ensure that the result is exactly what you were looking for, as you can always make changes directly in the editor if needed.

Transform Element Formulas
The new Transform element within Salesforce Flows can make data manipulation much easier. Since mapping fields directly may not be the right approach for all scenarios, the option to either set a static value or use a formula are available as well.

The beauty of using a formula within the transformation directly is that it can be calculated for each item in the source collection, similar to the example below, where a Task should be created for each of the Opportunities.
In case the Forecast Category is already Commit, the Priority of the Task should be set to High and prioritized immediately. Once again, the Einstein sparkles highlight that generative AI can be used here as well to generate the formula.

Validate Input in Screen Flows
As we covered Validation Rules above, it would be a shame not to go through a Validate Input example, which is available for Screen Components within Screen Flows.
Practically, it checks the component’s level for you to ensure that the users are adding the information as expected. One aspect to keep in mind is that Validate Input works differently than Validation Rules, as the formula should be what you are expecting, not what should trigger the error. This means if the formula is evaluated as ‘true’, the input is valid, and the user can progress.
For example, let’s ensure that a text field will not contain more than 20 characters.
LEN(Input_Text) < 21

As of Spring ‘25, the error message for the Validate Input will also be displayed in real time for the user rather than upon clicking the next or finish button, as it was before, making the experience even smoother.
Remember this option next time you have to use a screen flow to create a record, especially as standard Name fields are limited to 80 characters for custom objects!

Flow Formulas
When it comes to Flow formulas, we have you covered:
Other Formulas
Formulas in Approval Processes
There are endless possibilities with approval processes in Salesforce, which also provide a great way to document the history of approvals on records. Read our Ultimate Guide for more context.
Roll-Up Formulas
Check out the following resources:
- Create Roll-up Summary Fields Using Salesforce Flow
- How to Create Roll-Up Summary Fields in Salesforce with Rollup Helper
Default Value Formula
The formula editor can be used to prefill text fields with placeholder text. This is an underused feature that can help ensure data is entered in the correct format.

Summary
Formulas are here to stay. Whether you choose to calculate certain values in a report formula to save you from creating an extra field or you save the business a few clicks by using a formula field to display data from a related record, day-to-day processes are sure to involve at least one of them.
What do you think of our Salesforce formula examples? Is there a formula that has saved the day for you? Feel free to share your experience in the comments section below.
Comments: