Formula
Logical functions and operators
Logical functions and operators are used to evaluate conditions and return boolean values (TRUE or FALSE). They are essential for controlling the flow of calculations and making decisions based on specific criteria.
There are two different ways of performing logic operations within formulas:
- Logical functions: These are built-in functions that perform logical operations. Examples include
AND(),OR(). - Logical operators: These are symbols that represent logical operations. Examples include
&&(AND),||(OR).
Logical operators should always be the preferred choice over logical functions. This is because logical operators are more concise and easier to read, especially when dealing with complex conditions.
Example
Bad:
OR(
AND(
Stage == Sent,
Value < 50000
),
AND(
Stage == Not Sent,
Value > 50000
)
)
Good:
(Stage == Sent && Value < 50000) || (Stage == Not Sent && Value > 50000)
URLs in formulas
URLs are commonly used within formulas for several reasons:
- Link to a custom component
- Open a related record
- Navigate to an external webpage
- Display an image within a field
When using a URL to link to an internal page, regardless of what it is being linked to, use a relative URL. This allows the field to work seamlessly in any environment (e.g. production, sandbox, etc.) without needing to change the URL.
Whenever referencing an external resource, always use a fully formed absolute URL, e.g. https://google.co.uk
Specific page
- Bad:
https://fast-speed-5595-dev-ed.scratch.my.salesforce-setup.com/lightning/setup/SetupOneHome/home - Good:
/lightning/setup/SetupOneHome/home
Static resource
- Bad:
https://dev--c.sandbox.vf.force.com/resource/1743418923000/MyImage.png - Good:
/resource/MyImage.png
When linking to static resource, do not include the timestamp part of the URL (e.g. 1743418923000 in the example above) which may be obtained when inspecting the resource in the browser.