Salesforce Stack Exchange is a question and answer site for Salesforce administrators, implementation experts, developers and anybody in-between. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

When I do an upsert DML which trigger code will handle it?

  1. Insert
  2. Update
  3. Both


Is there a pattern to solve potential duplicate executions if it is 3)?

share|improve this question
up vote 16 down vote accepted

For records that already exist, it will fire updates. For records that are new, it will fire inserts. As a result, an upsert can cause both insert and update triggers to fire if you have both new and existing records in your upsert, but they both won't fire for the same record.

share|improve this answer

I've got a feeling that when you upsert records it does the inserts and the updates in separate batches. I can't find this documented though!

So for example you should be able to iterate through in an after insert and be confident that every record in is indeed a newly inserted record.

share|improve this answer

I put some debug into my trigger and found an upsert is running the Insert first and then the Update.

I also have an issue where I want followup processing on the parent records for the inserts and updates but if children of the same parent are involved in both the insert and update the processing runs twice.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.