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
Ankit Kalsara 14Ankit Kalsara 14 

Auto Populate a Customer Lookup field with the Current User

Hi all,

I need to populate current user info when I create a new record. Username should apper before saving the record.

I wrote the trigger but it populates the current user info after I save the record.

I need to pre-populate the current user info when I create the new record.

Below is my trigger code.

trigger populate_current_user on Applications_Time_Tracking__c (before insert) {

    // populate the current user name on record creation 
    for(Applications_Time_Tracking__c tt : Trigger.new){

        if(tt.User__c == null){

            tt.User__c = UserInfo.getUserId();   
        }
    }

Can you please help.