You need to sign in to do that
Don't have an account?
SalesforceBeginner
Trigger to populate Lookup field on Opportunity
Hi,
I am new to Salesforce triggers. I want to populate the custom lookup "Contact Name" field on Opportunity screen whenever Lead gets converted.
Thanks,
SFBeginner
Can you try the following?
All Answers
Can you try the following?
If you want to access the lookup object fields in the trigger context, it is not possible directly, only related field will be accessed, in order to access all the fields, need to query the look up object.
Thanks a lot wt35.
trigger testConversion2 on Lead (after insert,after update)
{
List<Opportunity> opps = new List<Opportunity>();
Map<Id,Id> association = new Map<Id,Id>();
for(Lead l : Trigger.new)
{
if(l.IsConverted && (l.ConvertedOpportunityId != null) )
{
association.put(l.ConvertedOpportunityId, l.ConvertedContactId);
}
}
opps = [SELECT Purchasing_Contact__c FROM Opportunity WHERE Id IN : association.keySet()];
for (Opportunity o: opps)
{
o.Purchasing_Contact__c = association.get(o.Id);
}
update opps;
}