Activity Forums Salesforce® Discussions Is apex trigger similar to validation rule in Salesforce?

  • shradha jain

    Member
    August 21, 2018 at 9:50 am

    Hello Anurag,

    Validation Rule : Validation rules verify that the data a user enters in a record meets the standards you specify before the user can save the record. Validation rules also include an error message to display to the user when the rule returns a value of “True” due to an invalid value.
    Eg : A very basic validation for start date and end date, a start date cannot be greater than the end date, this can be handled using the validation rule, where you specify the formulae as (StartDate > EndDate) - Display Error ("Start Date cannot be greater than End Date"). Your record will not be saved unless you your formulae becomes false.
    Validation rules apply to new and updated records.
    You cannot perform  DML operation and many other things that a trigger can do.

    Trigger : Apex triggers enable you to perform custom actions before or after changes to Salesforce records, such as insertions, updates, or deletions. A trigger can be used to perform some update on the same record or a related record based on some business criteria, can be used to perform DML operation on other records that meet some business criteria, can be used to send email, invoke a future HTTP callout etc.
    Eg : A typical use of trigger would be to say update a contact field on Account, whenever a new Contact is inserted. To meet this requirement, you will write a trigger on contact, which will perform an update on the associated Account.

    At the end it would depend on your actual requirement, just to check if the data entered is valid, use validation rule, to perform other complex business operations, use trigger.

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos