Salesforce Checkbox Validation Rule with Examples

While creating the job application form in Salesforce, I need to add a validation so that if the applicant selects the “Certification Done” checkbox, they must also provide details in the “Certificate” field.

This ensures that applicants who have completed a certification must enter the certificate name or details before saving the record.

The validation rule will prevent the user from saving the record if the checkbox is selected and the certificates field is empty.

In this article, we will learn about the Salesforce checkbox validation rule. In this, I will create a validation rule for a checkbox and explain how it works in a real-time scenario.

Why use the Checkbox Validation Rule in Salesforce?

A checkbox validation rule is useful when you want to ensure that if a user selects (checks) a checkbox, they must also provide other required information before saving the record.

As we saw in the above scenario, if a user checks the “Certification Done” checkbox, it means they must have a certificate.

  • Without a validation rule, a user could check the box but leave the certificate field blank, which creates incomplete data.

So here, the checkbox validation rule makes another field required only when the user selects the checkbox. This ensures that additional details are provided whenever the checkbox condition is true.

  • With a validation rule, when a user checks the checkbox, they must also provide the certificate details; otherwise, Salesforce will not allow the record to be saved.

Add Salesforce Checkbox Validation Rule

Below, I will explain how to add a checkbox validation rule in Salesforce so that whenever a user checks the checkbox, they must also fill in the related field. If they don’t, Salesforce will stop them from saving the record.

  1. Before adding the validation rule, if a user checked the ‘Certification Done‘ checkbox but did not fill in the ‘Certificate‘ field, Salesforce still allowed the record to be saved.
validation rule for checkbox field in salesforce
  1. Here, you can see that the record has been successfully created without any errors.
checkbox error state in Salesforce
  1. Now let’s add a validation rule on the checkbox field to display an error message when the checkbox is checked and another field has a Blank Value.
  • For that, click on “Setup.” -> Select the Object Manager tab ->Select the Object on which you want to create the Validation Rule. Here, I’m going to create a Job Application custom object.
  • Now select the Validation Rules and click the New button to create the new validation rule.
How to Add Checkbox Validation rule in Salesforce
  1. Now, enter the Rule Name and check the Active checkbox to apply the rule. Then, enter the logic for Error Conditions in the Formula Editor.
AND(
    Certification_Done__c = TRUE,
    ISBLANK(Certificate__c)
)
  • In the above formula, we have used the AND() function, which checks all conditions inside it. If the condition is true, then we will throw an error, which will prevent the record from being saved.
  • Certification_Done__c = TRUE: If user has checked this field that means they has done certification.
  • ISBLANK(Certificate__c): Additionally, if the user has done certification but does not provide the certificate names, an error will be triggered.

Click “Check Syntax” to ensure the formula is correct.

Enter Error Condition Formula in Salesforce Validation Rule
  1. Error Message: Now, enter a message to display an error when the user enters incorrect details. 
    • Error Location: Where the error message should display on the screen. For that, we have the following two options.
    • Top of Page: The error message will display beside the Save button.
    • Field: The error message will display on a particular field for which we apply validation.
    • Then click on the Save button.
Error Message in Checkbox Validation Rule

In this way, we can create the validation rule on a checkbox field in Salesforce. To apply this validation, ensure that the rule is activated.

Salesforce Checkbox Validation Rule

Proof of Concept:

Now, let’s navigate to the Job Application object and try to create a record by checking the Certification Done checkbox without providing the Certificate details.

Earlier, the record was getting saved, but now Salesforce prevents the record from being saved until the required information is entered.

Add Checkbox Validation rule in Salesforce

Now, let’s provide the certification details and try again. Click the Save button to create the record.

How to Add Validation On Checkbox in Salesforce

You can see that this time, Salesforce allows the record to be saved successfully because both the checkbox is checked and the required Certificate field is filled in.

Add Validation On Checkbox in Salesforce

In this way, we can use the checkbox validation rule in Salesforce to make the other field required if the checkbox is checked.

Conclusion

I hope you now have an idea of how to add a validation rule on a checkbox field in Salesforce. In this example, we saw how a checkbox can be used to make another field required only when it is selected.

This means that if the user checks the checkbox but leaves the related field blank, Salesforce will not allow the record to be saved.

You may like to read:

Agentforce in Salesforce

DOWNLOAD FREE AGENTFORCE EBOOK

Start with AgentForce in Salesforce. Create your first agent and deploy to your Salesforce Org.

Salesforce flows complete guide

FREE SALESFORCE FLOW EBOOK

Learn how to work with flows in Salesforce with 5 different real time examples.