Apex Scenario#1: Building custom validations | www.sfdctelugu.in


 Scenario: Building custom validations

Sometimes, you need to enforce specific business rules that cannot be accomplished using the standard validation rules in Salesforce. In such cases, you can use Apex to build custom validations.

For example, let's say you want to enforce the following business rule: If a Contact record has the value "High" in the Priority field, the Lead Source field cannot be blank.

Here's the code to implement this validation:


In this code, the validateContact method takes a Contact record as an input, and checks if the value of the Priority field is "High" and the Lead Source field is blank. 
If both conditions are true, it adds an error message to the Lead Source field, which will prevent the record from being saved.

To use this validation, you would add a trigger on the Contact object that calls the validateContact method before insert or before update. 

Here's an example trigger:



This trigger will call the validateContact method for each Contact record being inserted or updated, and enforce the custom validation.


For More: Visit SFDC STORE

 e-Book Store

S F D C  T e l u g u

Steps:
  1. Click on eBook
  2. Fill the Details (mail id must be correct)
  3. Select Payment method
Note: 
  • you will get eBook pdf given Gmail id within 0-2 hours.








 


Thank you,
SFDC e-BOOK STORE.


Post a Comment

0 Comments