Formulas
See Also Rules for Fields
Getting Started
Trailhead has a good overview of Formulas https://developer.salesforce.com/trailhead/force_com_introduction/point_click_business_logic/formula_fields and rollup summary fields https://developer.salesforce.com/trailhead/force_com_introduction/point_click_business_logic/roll_up_summary_fields and Validation Rules https://developer.salesforce.com/trailhead/force_com_introduction/point_click_business_logic/validation_rules
This is a nice overview of formulas for Salesforce
Formula Pages
Other pages in this site about formulas
-
Case Thread ID — Used in Cases to ensure that an email sent to your support email is attached to an existing Case.
Articles about Formulas
Example Formulas
The Salesforce help has some nice examples https://help.salesforce.com/HTViewHelpDoc?id=useful_advanced_formulas.htm and date formulas https://help.salesforce.com/HTViewHelpDoc?id=formula_examples_dates.htm
Date Expired on Active Contract Example
Requirement for a field for an expired contract. Users requested a report they can run to show if the contracts are expired (note, this is using a custom contracts object so this can be used on any type of record.
Checklist Formula field.
- If Statement - straightforward, just as you would have used in Excel.
- And Statement - exactly like Excel
- A field value > Today()
- ISPICKVAL formula - you need to use this wherever dealing with the picklists.
- And returning True or False because the formula is a
Date Expired check field 2 weeks before Active Contract Example
Requirement for a field to check an expired contract or create a warning. Workflows can be created to task a record owner to check a contract
As above but include "-14" for 14 days before expiry
State and Country for use with State and Country Picklists
IF(NOT(ISBLANK(BLANKVALUE(TEXT(BillingStateCode) ,TEXT(ShippingStateCode)))),
BLANKVALUE( TEXT(ShippingStateCode) ,TEXT(BillingStateCode)) & IF(BLANKVALUE(TEXT(ShippingCountryCode), TEXT(BillingCountryCode)) = "AU","", ", " & BLANKVALUE(TEXT(ShippingCountryCode), TEXT(BillingCountryCode))),"")
/*IF(NOT(ISBLANK(BLANKVALUE(TEXT(BillingStateCode) ,TEXT(ShippingStateCode)))),
BLANKVALUE( TEXT(BillingStateCode) ,TEXT(ShippingStateCode)) & IF(BLANKVALUE(TEXT(BillingCountryCode), TEXT(ShippingCountryCode)) = "AU","", ", " & BLANKVALUE(TEXT(BillingCountryCode), TEXT(ShippingCountryCode))),"")*/
Warning fields
Requirement for a field to create a warning that a contract if about to expire
IF (ContractExpiry__c = True, "Contract about to Expire","")
If adding more than one warning add + '; ' + between IF statements
Add a Year to a Date Example
As described here
https://success.salesforce.com/answers?id=90630000000gmVpAAI
Things you can't do
- You can't do a roll up summary field on a formula field!!!! https://success.salesforce.com/ideaview?id=08730000000Bra0AAC (caveat - if it has cross object formulas - seehttp://blog.wdcigroup.net/2012/07/salesforce-tips-roll-up-summary-with-formula-fields/) Workarounds:
- Use Rollup Helper.
- Use workflows to update a the field on the child object, then you can sum it. http://focusonforce.com/configuration/salesforce-roll-up-summary-using-the-value-of-a-formula-field/
- Don't use cross object formulas in the child object
- Flows
- Process builder?
Rules
Rules for Formulas:
- Use Comments - See Trailhead for an example https://developer.salesforce.com/trailhead/force_com_introduction/point_click_business_logic/formula_fields
- Space out your formulas so you can read them.
- eg each section of an AND formula on a new line
- See Enhanced Formula Editor in Useful Google Chrome Extensions for Salesforce to see how to show your formulas in colour.