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
shawnnshawnn 

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.

Best Answer chosen by Admin (Salesforce Developers) 
Pradeep_NavatarPradeep_Navatar

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

Nick34536345Nick34536345

Yeah I expect a lead trigger would do this - there are "ConvertedContactId" and "ConvertedAccountId" fields on the Lead object which would help.

 

Pradeep_NavatarPradeep_Navatar

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.

This was selected as the best answer