About this question
I understand that trigger.new contains the list of my records with new values of the records. My questions are:
If multiple users work on the same single object and they do an update should I use Trigger.new or trigger.new[0]?
If multiple users work on different records of the same object(say lead) and they do an update should I use Trigger.new or trigger.new[0]?
As an example when a Lead is being converted, I need to check that a contact with the same email does not exist (I know I can do it in duplication rules, but I am doing it in trigger). Now what I did was:
if(!trigger.new[0].status.equalsIgnoreCase('Qualified')) { List existingContacts = [ SELECT Email FROM Contact WHERE Email =: trigger.new[0].Email LIMIT 1 ]; if(!existingContacts.isEmpty()) { trigger.new[0].addError('A contact already exists'); } } Is it ok to use trigger.new[0] in the above case, as one/more users will convert only one lead at time?
When is ok to use trigger.new[0] and not ok to use trigger.new[0]? I know if you are working on mass records like mass update or mass delete etc., obviously we have to use trigger.new and not trigger.new[0]. But any other scenarios?