You need to sign in to do that
Don't have an account?
Ankit Kalsara 14
How to auto-populate user in custom lookup field
Hi team,
I have written trigger to auto-populate current user on custom lookup field for custom object. However it does not work. Any idea how do we populate current user on custom lookup field ?
trigger populate_current_user on Applications_Time_Tracking__c (before update) {
// populate the current user name on record creation
for (Applications_Time_Tracking__c record : Trigger.new) {
record.User__c = UserInfo.getUserId();
}
}
I have written trigger to auto-populate current user on custom lookup field for custom object. However it does not work. Any idea how do we populate current user on custom lookup field ?
trigger populate_current_user on Applications_Time_Tracking__c (before update) {
// populate the current user name on record creation
for (Applications_Time_Tracking__c record : Trigger.new) {
record.User__c = UserInfo.getUserId();
}
}
Things to check:
Make sure the trigger is active.
Make sure User__c is a Lookup field to the User object
I just checked the same functionality on Contact by creating a new lookup field to User, it is working as expected.
Sorry for this issue you are facing.
May I suggest you please try the sample code below which works fine for me. Hope this helps.
Kindly mark this as solved if the reply was helpful so that it gets removed from the unanswered queue which results in helping others who are facing a similar issue.
Thanks,
Nagendra
Hi Apuroop, Nagendra,
The code provided by you works well after the record is created.
My requirement is to populate current user when the user inputs the data for the object (before he clicks on save button)