• Ankit Kalsara 14
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 5
    Replies
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();    
   }
}
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.
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();    
   }
}
Hello, 

new to Triggers, we want to populate a custom lookup field with the current user when an opportunity is closed. 

For example, we have a custom field called closed_by__c which is a lookup to the user object. When a user selects "Closed" from the standard stagename field we want to have the users name populated in the closed_by__c 

I've spent a ton of time looking through the forums but I haven't come across somebody with the same situation. 

any thoughts on how to do this ?
here is what I started with
trigger updateClosedByField on Opportunity (after insert, after update){
for(opportunity opp : trigger.new) 
 
 {
 
    opp.closed_by__c = opp.StageName;
    }
    
    }

 
I have two custome fields in my opportunity. right now the fields are being field manually. one filed is a checkbox, and what I want is as soon as an that check mark is checked, the name of the person that has checked it to be in another field under it . So I have Check1__c being checked, 

and I have NameUpdate__c to be field up by my name since I am workign on this opportunity right now

Hi

We have a custom lookup field that has been created on the Opportunity Line Item object called Product Owner. We would like this to be auto populated with the current user when left blank upon saving. 

We've tried to create a trigger to do this but run into errors upon saving the product line

trigger updatefield on OpportunityLineItem (after insert) {
  user defaultuser = [select id from user where name = 'default user'];
  for (OpportunityLineItem record:trigger.new) {
    if(record.Product_Owner__c ==null) {
      record.Product_Owner__c = defaultuser.id;
    }
  }
}

Any help or advice would be much appreciated.

Thanks,

Snita