+ Start a Discussion
Eager-2-LearnEager-2-Learn 

Who is running the process?

Because I am using a job to update opportunity records every night.  SFDC will automatically put my name on the LastModifiedBy field.  This over writes the user who last touched the record; therefore, I have created a custom field to store the LastModifiedBy value in the custom field prior to updating the record.

 

The problem is that I do not want to put any value in the custom field is the last modified by name is my name or who ever ends up submitting updates of this class code into production and schedules the job.

 

Bottom line, how can I programmatically get the user's name who is running the job/code?

I appreciate your help.

Best Answer chosen by Admin (Salesforce Developers) 
ca_peterson_oldca_peterson_old

One tip that comes from experience, make your custom lastModifiedBy field a lookup to the user object instead of a text field, and put the user's ID into that lookup rather than the user's name.

 

This will show as a link to the user record in the UI (which is better than just the name), and will update if the user's name ever changes, as well as being better for reporting, etc.

 

To get the user's ID you want the UserInfo.getUserId(); command.

All Answers

Eager-2-LearnEager-2-Learn

I think I found this one on my own:smileyhappy:

 

UserInfo.getName()

 


Trying now to see if it work like I want it to.  Thanks.

ca_peterson_oldca_peterson_old

One tip that comes from experience, make your custom lastModifiedBy field a lookup to the user object instead of a text field, and put the user's ID into that lookup rather than the user's name.

 

This will show as a link to the user record in the UI (which is better than just the name), and will update if the user's name ever changes, as well as being better for reporting, etc.

 

To get the user's ID you want the UserInfo.getUserId(); command.

This was selected as the best answer