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

I'm writing a trigger to update another object's field. I know a trigger can fire on multiple records. My question is if the records are unique? E.g. A trigger is called with 5 records. Does SF guarantee that each of the 5 records are different or could the same record be in the list twice? I want to use a Map and thought to use the object's ID as the key.

The first example [in this link] ( implies a record can appear more than once as it uses a set to guarantee uniqueness.

Thanks, Scott

share|improve this question
up vote 8 down vote accepted

Yes, the records are unique. In fact, in an ApexTrigger or the context of a trigger specifically, you can use Trigger.newMap (which is populated on after insert, but not before insert) and also Trigger.oldMap in place of creating your own map.

Here's a link to the Trigger Context Variable documentation for more info on the maps and when they are available:

share|improve this answer
Thanks for the confirmation. I've been looking for documentation guaranteeing such behavior but found nothing that specific. Paranoid I am, but when messing with a company's data a healthy dose of paranoia goes a long way! :-) – Scott Feb 14 '14 at 21:48
No problem. It's worth to note that the records are guaranteed to be unique by id, but not necessarily any other criteria. Meaning that your trigger may contain records that have the same email addresses or other dedupe criteria. As an example, if you import 100 records with 5 distinct emails in data loader, your trigger will run over 100 records. – James Loghry Feb 14 '14 at 21:54

In a trigger, all of the records are unique. If you have the same record in a list twice and do a DML, salesforce will actually throw an error. Make sure you do not place the same record twice in a list.

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.