Monday, May 18, 2015

Salesforce Validation Rule: Text field is required when checkbox field is checked.

Take an example a company uses Salesforce CRM in their organization. A user has come to you with request that when the “Do Not Call” field on contact object is checked then it’s mandatory for users to enter the reason in Reason field. How can this be done using Conga Composer?

The system administrator needs to create validation rule on Reason field.

Navigation: Setup > Customize > Contacts > Validation Rules

Rule Name: Enter the name

Active: Select to make validation rule active.

Description: Optional

Error Condition Formula: AND(  DoNotCall = TRUE, OR( ISBLANK(  Reason__c  )))

When “Do Not Call” field is “True” then “Reason” field cannot be blank. Check Syntax for errors.
Error Message: Enter the error message when formula condition is true.

Error Location: You can select “Top of Page” or Field and save.

Now on contact detail page “Do No Call” field is checked. When I try to save the record without entering the reason it displays an error that I need to enter text in Reason field before I can save the record.

Now sometimes you want to exclude some profiles from validation rule. For example: I don’t want error to be displayed as a system administrator when saving record. Hence I need to make comes changes to the condition formula in validation rule.

I added an extra line: $Profile.Name <> "System Administrator". Where <> is Not Equal. System administrator should be able to save the record.

System Administrator was able to save the record without entering the Reason when Do No Call field was checked. For other profiles the error will be displayed.