I have an opportunity trigger that runs before insert and before update. It has a recursive check on the before update and a separate one on the before insert so that each only run once. I am pushing a batch of opportunities via upsert, some are updates only and some are inserts only. What I see happening is that the before insert triggers and my logic occurs. Then before update occurs on the same opportunity and then all my updates never go through the trigger logic.

I am not sure why the update is also occurring on the insert record. I am passing trigger.new which I believe should hold the entire batch.

My if conditions on the triggers are as follows

/*for before update*/

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



/*for before insert*/

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

  • Do you have any workflow rule updates or process builder which may be updating the record after its inserted? – Jayant Das Apr 26 at 16:46
  • It's likely your recursion check may be incorrect. Also, if your upsert has a combination like [insert, update, insert, update], then your recursion check may block some of the attempts. – sfdcfox Apr 26 at 17:07
  • @sfdcfox would an upsert on a record that is brand new cause an insert and then an update? Or would that be some flow triggering that update after insert? – MarkC5000 Apr 26 at 17:51
  • @MarkC5000 upsert only triggers insert/update triggers if at least one record matches the situation. Flows, Processes, Workflow Rules, etc can cause triggers to run more than once in the same transaction. – sfdcfox Apr 26 at 17:56
  • @sfdcfox it seems like this is related to a process being called then. I am just using trigger.new so when the process builder fires, it calls the update trigger on the one that was just inserted, but I don't want that to happen. I only want the update to fire for the people that have updates. Is there any way in code for me to prevent the update trigger for firing for this? – MarkC5000 Apr 26 at 19:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.