Basic Apex Trigger Modifying Data

PHOTO EMBED

Sat Jul 24 2021 16:15:19 GMT+0000 (Coordinated Universal Time)

Saved by @yinmaster #apex #salesforce #trigger

trigger AccountTrigger on Account (before insert) {

      if(Trigger.isInsert && Trigger.isBefore) {

        
        List<Account> myList = new List<Account>();

        for(Account acct : Trigger.new){
          if(acct.name == 'My Test Account'){
           acct.AnnualRevenue = 0;
           myList.add(acct);
          }
        }

        if(myList.size() >= 0){
          insert myList;
        }
      }   
}
content_copyCOPY