You need to sign in to do that
Don't have an account?
![JDegner JDegner](https://dfc-org-production.my.site.com/img/userprofile/default_profile_45_v2.png)
Update custom lookup field
trigger timecardGetUser on SFDC_Service_Timecard__c (before insert, before update){ SFDC_Service_Timecard__c a = Trigger.new[0]; a.User__c = UserInfo.getName(); }
I'm trying to update a custom lookup field with a trigger. I have the code included. When I create a new timecard, the User__c filed isn't being updated! Any ideas?
Hi, you need to assign it the Id of the User...try UserInfo.getUserId();
Keep in mind anytime in apex when you do assignments to lookup relationship, master/detail, objects, etc...Apex will need the record Id, even though on the front end UI salesforce will display the physical name or text.