Formulas and Validations
These are technical notes I compiled while studying using Trailhead, Salesforce's free self-learning portal.
Use Formula Fields
Create a custom formula field and use the formula editor. Explain why formula fields are useful. Outline at least one use case for formula fields. Create simple formulas.- Easy examples are cross-object formulas. Examples:
- On Contact:
Account.AccountNumber
- On Opportunities:
CloseDate - TODAY()
- “Power of One” (can be added to any object):
1
- Provides a way of counting the number of unique objects in a report with many records.
- If there are a hundred opportunities in a report, but only a handful own them, creating a
Unique Users
formula field with number return type and formula1
- In a report, add this new field, then summarize that field using a
Sum
- On Contact:
Implement Roll-Up Summary Fields
Describe what a roll-up summary field is. Create a roll-up summary field. Apply field-level security to your roll-up summary field.- Roll-Up Summary fields calculate values from a set of related records, such as those in a related list
- Available types:
COUNT
,SUM
,MIN
,MAX
- Examples:
- Sum of Opportunities on an Account
- Date Opportunity First Created
- Total Price of All Products Related to an Opportunity
- Minimum List Price of an Opportunity
- Available types:
- Types of fields available depend on the type of calculation:
- Number, currency, and percent fields are available when you select SUM as the roll-up type.
- Number, currency, percent, date, and date/time fields are available when you select MIN or MAX as the roll-up type.
Create Validation Rules
Describe two use cases for validation rules. List the elements of a validation rule. Create a validation rule.- When the validation rule returns a value of “True”, this confirms that the data entered by the user contains an invalid value.
- Examples:
- Account Number Length not correct:
LEN(AccountNumber) != 8
- Account Number Is Numeric:
AND(NOT(ISBLANK(AccountNumber)),NOT(ISNUMBER(AccountNumber)))
- Date Must Be in Current Year:
YEAR( My_Date__c ) <> YEAR ( TODAY() )
- Number Range Validation:
(Salary_Max__c - Salary_Min__c) > 20000
- Website Extension must be “.com”:
AND(RIGHT( Web_Site__c, 4) <> ".COM", RIGHT( Web_Site__c, 4) <> ".com")
- Account Number Length not correct: