• scenario: Before Delete Trigger in Salesforce

    Published By: Venu Gutta
    Published on: Tuesday 21 March 2017
    A- A+
    Before Delete Triggers basically used for preventing the record deletion based on some condition.

    Scenario: Write a Trigger on Account to prevent the record delete, if Annual Revenueis grater than or equals to 50,000. If Annual Revenue is more than fifty thousand it should throw error.

    Trigger:

    trigger DeleteTrigger on Account (Before Delete) {
    If(trigger.isBefore){
       If(Trigger.isDelete){
           for(account a: trigger.old){
               if(a.AnnualRevenue>=50000){
                   a.adderror(' You cant delete if "Annual Revenue is more than 50000" ');
                     }
                 }

            }
       }
    }

    If I try to delete Account Record which has more than 50,000 then it shows Validation Errors While Saving Record(s) like below


  • No Comment to " scenario: Before Delete Trigger in Salesforce "