<img height="1" width="1" style="display:none" src="https://www.facebook.com/tr?id=1703665079923990&amp;ev=PageView&amp;noscript=1">
Skip to main content
How to Write Salesforce Formulas like a Pro
4:21

Whether you're writing a validation rule, building a custom formula field, adding a row-level formula in a report, or working with formula variables inside a flow, these tips apply everywhere Salesforce uses formula syntax. The examples below use a validation rule to keep things concrete, but the principles are universal.

**Throughout this article, we'll use one consistent scenario: a sales manager wants Opportunities to become read-only once they've passed their close date. Simple enough, but complex enough to show off all seven tips in action.

Formula Hero

 

Table of Contents

 

Tip #1: Always Add a Description

It sounds obvious, but it's the tip most commonly skipped. Every validation rule should have a clear, descriptive name and a written description of its purpose. Six months from now, when a different admin needs to edit it, that description is the difference between a quick fix and an hour of archaeology.

Best practice: Write your description before your formula. Describing the intent in plain English first often clarifies the logic and makes the formula easier to write.

Tip1

 

Tip #2: Write Functions in UPPERCASE

Using uppercase for function and keyword names, and keeping field names in the case they were saved in, makes it immediately clear what's a built-in function and what's your data. At a glance, you can tell TODAY() apart from CloseDate.

The second version is instantly more readable — functions stand out, field names are recognizable.

 

 BeforeTip2_1                 

After

Tip2_2  

Tip #3: Skip the = TRUE on Boolean Fields

When evaluating a Boolean (checkbox) field, you don't need to write = TRUE. The field itself evaluates to true or false during formula execution; the comparison is redundant.

Conversely, if you're checking that a Boolean is false, you can write NOT(IsClosed) or use the ! operator — no need for = FALSE either.

Tip3

 

Tip #4: Use Shorthand Operators 

Salesforce supports shorthand logical operators that many admins aren't aware of. These can significantly reduce nesting, especially as formulas grow in complexity.

Function
Operator
Meaning
AND (X, Y) X && Y Both must be true
OR (X, Y) X | | Y Either must be true
NOT (X) !X Invert the result

 

Operators often reduce the visual nesting level, making complex multi-condition rules far easier to scan and understand.

Tip4

 

Tip #5: Use Comments – For Two Reasons

Formula comments are human-readable text wrapped in /* ... */ that the Salesforce compiler ignores completely. They won't trigger errors, and they don't count toward your character limit. There are two compelling reasons to use them:

  1. Documentation: Explain why the rule exists, who requested it, and what edge cases it handles. Your future self,  and every admin after you,  will be grateful.

  2. Troubleshooting: Temporarily comment out individual conditions to isolate bugs in complex multi-condition rules. It's the formula equivalent of console.log debugging.

Tip5_1

Here is an example of a commented validation rule with some logic commented out for troubleshooting purposes.
 
Tip5_2
 
 

Tip #6: One Function Per Line


Whitespace is free. Putting each function, condition, or major clause on its own line costs nothing — and makes your formula dramatically easier to scan, review, and edit.

This is especially valuable for longer rules with nested logic. Structure your formula like code, not a run-on sentence.

Think of formula indentation the same way a developer thinks about code indentation: nesting levels should be visually obvious, not buried in a wall of text.

Tip6

 

 

Tip #7: Learn more!


Salesforce has outstanding formula documentation like operators, built-in functions, advanced best practices, and dozens of real-world examples. It's regularly updated and genuinely useful at every experience level. Make it a permanent fixture in your admin toolkit.

Save this link: Salesforce Formula Reference → Covering operators, functions, additional best practices, and loads of examples.

Reading through the function library once (even just skimming) will surface capabilities you didn't know existed and spark ideas for formulas you might be overcomplicating today.

Darrin Hearn

 

Meet Your Author: Darrin Hearn

Darrin is a Solution Consultant who enjoys solving problems and helping customers work smarter, not harder. He works to tailor solutions that help achieve business goals and provide value. When not advising customers, he enjoys spending time with his family, fostering dogs, and supporting local charities.