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
raviteja p 21raviteja p 21 

how to fields autopoplate based on lookup field before save the record it can be autopoplate?

Ajay K DubediAjay K Dubedi
Hi raviteja p 21
Please try below code.
Using  trigger we will get the auto populate the Lookup field values.

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 = userinfo.getUserId();
    }
  }
}

Let me know if you have any query.
Mark it as a best answer if it help you.

Thanks,
 Ajay Dubedi
Bhargavi TunuguntlaBhargavi Tunuguntla
Hi

Yes it can be autopopulated if its a visual force page but this doesn't happen if its a standard page.After save we can set the values through trigger or process builder or other automations. but doesnot happen once the lookup value is selected .

Thanks