function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
h20riderh20rider 

before update/insert trigger

I have a trigger that I update before wether a insert or update. The problem that I am having is that I update the value in the trigger before section.  But for some reason that update to the object is trigger another update.  Is there a way to either not have the trigger, trigger the update after or capture the object before the trigger.

 

Thanks

 

JWG

Best Answer chosen by Admin (Salesforce Developers) 
craigmhcraigmh

If you have a trigger like this:

 

trigger testTrigger on Account (before insert, before update) {
   for(Account a: trigger.new) {
      a.CustomField__c = 'trigger value';
   }
}

 Notice how there is no DML statement. If you are modifying the trigger.new collection BEFORE insert and/or update, you don't need to do anything other than to assign the value.

All Answers

donkotterjrdonkotterjr

Hey h20rider, 

Updatinng based on triggers can be tricky.  There are definitely some techniques to work around these complications.  

Without seeing your code I wouldn't be able to advise you directly.  Please specify if you are trying to update the same object that fires the trigger. 
Also feel free to contact us if you'd like some additional help! 

craigmhcraigmh

If you have a trigger like this:

 

trigger testTrigger on Account (before insert, before update) {
   for(Account a: trigger.new) {
      a.CustomField__c = 'trigger value';
   }
}

 Notice how there is no DML statement. If you are modifying the trigger.new collection BEFORE insert and/or update, you don't need to do anything other than to assign the value.

This was selected as the best answer
donkotterjrdonkotterjr

Good point!

h20riderh20rider

thanks everyone.  it turns out the before trigger was not firing an update.    sorry for taking so long to respond.