function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
cmoynihancmoynihan 

LastModifiedById is the old value in trigger.new

I have a before trigger running on Cases where I am checking a few fields for changes, and notifying the Case Contact owner via email.

 

I am using trigger.new and grabbing the LastModifiedById from the record, but it seems to be the previous person who made the update (the old record value) not the person who just made the update (the new record value).

 

Is that field updated after the record is committed? And if so, how can I find out who made the changes to the record so I can include it in my notification? 

Best Answer chosen by Admin (Salesforce Developers) 
nandurinanduri

Looks like LastModifiedById filed is only updated after the record has been updated. If you can change your triggering event to after update, you will be able to get both the values  Trigger.new[i].lastmodifiedbyId and Trigger.old[0].lastmodifiedbyId

All Answers

nandurinanduri

Looks like LastModifiedById filed is only updated after the record has been updated. If you can change your triggering event to after update, you will be able to get both the values  Trigger.new[i].lastmodifiedbyId and Trigger.old[0].lastmodifiedbyId

This was selected as the best answer
cmoynihancmoynihan

I moved that specific code to an after trigger and it works.

 

It was just weird because I couldn't find anything that made it clear those fields were updated post-record update.

Samy SaiedSamy Saied

I have the same problem, but unfortunately my code cannot be moved to the After Update, it must be triggered on Before Update.

 

In my case, I am basically trying to lock a record and only allowing certain user to edit this record. Anyone has an idea how to do that? The whole idea is that users can create Orders and once they change the Order status to OPEN, the orders must be Locked, and a System User can only edit this order.

Starz26Starz26

Samy Saied wrote:

I have the same problem, but unfortunately my code cannot be moved to the After Update, it must be triggered on Before Update.

 

In my case, I am basically trying to lock a record and only allowing certain user to edit this record. Anyone has an idea how to do that? The whole idea is that users can create Orders and once they change the Order status to OPEN, the orders must be Locked, and a System User can only edit this order.


You could:

 

Create a workflow, which on the change of your locl-field to true makes a field-update action, which change the record type to 'locked opportunity'.

Make a separate layout for this particular record type

 

OR

 

Use an approval process that loks the record (using code to put the record into the approval process and make sure the user cannot recal the approval request) if the Order status is open. To unlock, you would have to write code to automate the approval to unlock it....

 

The first option is eaiser.

 

To get specific users to be able to edit the record is tricky though....I believe they would have to have modify all data permission which means they could also view all......

Samy SaiedSamy Saied

The thing is that I already use the approval process for a different logic, and the locking I want is for all users (Except ONE only) when a field value is matched to a certain criteria.