You need to sign in to do that
Don't have an account?
shawnn
Lead Conversion
In the object account, I have a custom lookup field called Master Contact. What I wish to do is upon lead conversion, automatically fill that field with the new contact created in the conversion process. I'm hoping there is an apex-free solution, but to me it seems that some sort of trigger will have to be written. The issue here then would be trying to get the newly created contact's id and account's id.
Find below a sample trigger :
trigger trigMapFields on Lead (before update)
{
for(Lead lead:System.Trigger.new)
{
if (lead.IsConverted)
{
// Assign the value from the Account "MasterContact" lookup field to the ContactID"
system.debug('<!---------Convert Leads 222 --------->');
Account acc = [SELECT Id,MasterContact__c FROM Account WHERE Account.Id = :lead.ConvertedAccountId];
Contact con = [SELECT Id FROM Contact WHERE Contact.Id = :lead.ConvertedContactId];
acc.MasterContact__c = con.id;
update acc;
system.debug('<!---------Check Account Fields 111--------->' + acc.MasterContact__c);
}
}
}
This trigger would really help you to fill the custom field of an account.
Did this answer your question? if so, please mark it solved.
All Answers
Yeah I expect a lead trigger would do this - there are "ConvertedContactId" and "ConvertedAccountId" fields on the Lead object which would help.
Find below a sample trigger :
trigger trigMapFields on Lead (before update)
{
for(Lead lead:System.Trigger.new)
{
if (lead.IsConverted)
{
// Assign the value from the Account "MasterContact" lookup field to the ContactID"
system.debug('<!---------Convert Leads 222 --------->');
Account acc = [SELECT Id,MasterContact__c FROM Account WHERE Account.Id = :lead.ConvertedAccountId];
Contact con = [SELECT Id FROM Contact WHERE Contact.Id = :lead.ConvertedContactId];
acc.MasterContact__c = con.id;
update acc;
system.debug('<!---------Check Account Fields 111--------->' + acc.MasterContact__c);
}
}
}
This trigger would really help you to fill the custom field of an account.
Did this answer your question? if so, please mark it solved.