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
Sudeep SinghSudeep Singh 

How Lookup field can be auto-populated ?

I have a lookup field in Lead object and Contract Object.
Field Name -  Service 
Lookup with Product.

I need to auto-populate only one product in those lookup field in Lead as well as Contract before creatin record.

When we click on new button at that moment only the lookup field must have "Value" product.

Thanks
Best Answer chosen by Sudeep Singh
SubratSubrat (Salesforce Developers) 
Hello Sudeep ,

Requesting you to go through this discussion which is closest with your requirement -> https://developer.salesforce.com/forums/?id=9060G000000Bh9cQAC

​​​​​​
Hope it helps.
Thank you.

All Answers

Shri RajShri Raj

There are several ways to auto-populate a lookup field in Salesforce. Here are a couple of options:
Use a default value on the field: You can set a default value for the lookup field in the Lead and Contract objects. This will automatically populate the field with the specified product when a new record is created.
Use a trigger: You can create a trigger on the Lead and Contract objects that will automatically populate the lookup field with a specified product when a new record is created.

trigger AutoPopulateService on Lead (before insert) {
    for (Lead l : Trigger.new) {
        l.Service__c = [SELECT Id FROM Product WHERE Name = 'Value' LIMIT 1].Id;
    }
}
 
Sudeep SinghSudeep Singh
Hi Shri Raj,

Can you please let me know how to set a default value in lookup field, am not getting option for it.

Thanks
SubratSubrat (Salesforce Developers) 
Hello Sudeep ,

Requesting you to go through this discussion which is closest with your requirement -> https://developer.salesforce.com/forums/?id=9060G000000Bh9cQAC

​​​​​​
Hope it helps.
Thank you.
This was selected as the best answer