Q:

Why LastModifiedbyid in Trigger.new gives old value

I have noticed the strange behaviour of salesforce due to which even my code broke down in production.
I was trying to stop the user from updating some field..I used before udpate trigger and code like Trigger.new[i].LastModifiedbyId..
Ideally it should give the current user in Trigger.new[i].LastModifiedbyId in  but it gives oldrecordLastModifiedbyId..
Although userinfo.getuserid resolves the problem later.
Any idea about this behaviour of salesforce.

A:

System audit fields like LastModifiedById, LastModifiedDate, and SystemModStamp are not updated until later in the transaction. You shouldn't rely on any of those values being set, especially in a "before" trigger; even OwnerId might have the wrong value during a trigger, especially if assignment rules are going to be evaluated. Using UserInfo.getUserId() is the most accurate way to determine the current user modifying a record.
Edit: The fields LastModifiedById and LastModifiedDate, at least, appear to be set during step 6 (temporary save to database) in the Triggers and Order of Execution document. This means that an after trigger should, in theory, be able to perform the validations you're looking. Validation rules and before triggers are executed before this temporary record save, and will definitely see the wrong values.

