Sunday, December 18, 2022

Update a record on which we are writing the trigger

Use before insert or before update if you need to update or insert the record on which you are writing the trigger.

Trigger populate_userlookup on Book__c (before insert, before update) {
  for(Book__c b : Trigger.new) {
   b.buyer__c = b.ownerId;
 }
}

Note: No need to use DML statements like insert or update in case of before triggers.

No comments:

Post a Comment