Posts

Showing posts with the label Validation rule

Salesforce Fact #824 | Simplifed check in validation rule

Suppose we have a use case in validation rule, where we need to restrict the change of some fields for all persona and if the user has a particular custom permission set assignment then the validation stays the same except for one field. So, instead of repeating the condition check we can simplify the condition since few of the fields are anyways common: OR( ISCHANGED(AccountNumber), ISCHANGED(AnnualRevenue), IF(NOT $Permission.Test_Custom_Perm, ISCHANGED(NumberOfEmployees), FALSE) ) In the above example, the user is restricted to update Account number, Annual Revenue and Numberofemployees fields with the exception for  NumberOfEmployees if the user is assigned the  Test_Custom_Perm custom permission.

Salesforce Fact #722 | validation rule message for inaccessible field

We have two options to display validation rule error message in UI: Field/Top of page. Now, if the field is not present in the layout or if the user does not have access to the field, the error position gets changed to 'Top of Page' automatically. Reference:  https://developer.salesforce.com/docs/atlas.en-us.api_tooling.meta/api_tooling/tooling_api_objects_validationrule.htm

Salesforce Fact #580 | Check issandbox in validation rule and formula

Image
There is a field IsSandbox on Organization object which denotes whether the current org is a sandbox or not. But this field is not accessible using the $Organization global variable in formula field and validation rules. So, in order to check issandbox, we can create a custom metadata with a checkbox field and set it to true for sandboxes and keep it unchecked for non-sandbox orgs. Then we can refer this record in formula field and validation rules. Attached are the screenshots.

Salesforce Fact #3 | validation vs workflow

Validation rules are not triggered during workflow field update. Suppose, we have two fields F1 and F2. We have a workflow rule defined on the object such that when the value of F1 is 100, it sets the value of F2 to 200. And also we have validation rule defined with the condition as F2 == 200. Now, if we try to create or edit a record by directly modifying the value of F2 i.e. setting it to 200 we are going to encounter the validation error. However, if we create or update a record with the value of F1=100, which ultimately sets F2 to 200, in this case there won't be any validation error.