+ Start a Discussion
Gheorghe Sima 29Gheorghe Sima 29 

Trigger execution

Hi,

When a trigger fires it process the records modified by one user or more users? For example if 2 users edit one record each(from the same object) and click save in the same time then these 2 records will be processed in the same trigger execution or it will be 2 executions of the trigger?

If write userId = UserInfo.getUserId() in a trigger, what user id it will return?

Thanks!

Best Answer chosen by Gheorghe Sima 29
UC InnovationUC Innovation
I think the records would be processed in separate trigger exection since UserInfo needs to return a specific user.  This StackExchange question/answer confirms this:

http://salesforce.stackexchange.com/questions/2200/determining-user-invoking-action-within-trigger

All Answers

UC InnovationUC Innovation
That's a good question.  I think you would get a record locking error for one of the user instead though if two users update the record at the same time.
Gheorghe Sima 29Gheorghe Sima 29
What I want to say is that if two users edit 2 different record and then push the save button in the same time, these 2 records will be process in the same trigger execution?
JeffreyStevensJeffreyStevens
Ya - I agree - I think you would get both records in the trigger.new and old lists and maps.  But the question still remains - what would be the value of UserInfo.getUserI()?
Gheorghe Sima 29Gheorghe Sima 29
Another question that I have is how to get the id of the user that edit a record in a before update trigger? I tried to use the LastModifiedById but it has the same value in both the new version of a record and the old one.
UC InnovationUC Innovation
I think the records would be processed in separate trigger exection since UserInfo needs to return a specific user.  This StackExchange question/answer confirms this:

http://salesforce.stackexchange.com/questions/2200/determining-user-invoking-action-within-trigger
This was selected as the best answer
Gheorghe Sima 29Gheorghe Sima 29
Thanks  a lot. I want to control who edit some record in particular cases and i don't know a stardard way to do this. I write a trigger for that and i wanted to be sure that a trigger is executed for a single user.