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
NBP1411NBP1411 

Lead Conversion for SIC Code

Hi all,

I am trying to write a trigger to allow a custom Leads field (SIC Code) map over to the Account field SIC Code. How could I write this trigger?

Thank you.
 
@Karanraj@Karanraj
You don't need trigger code to do this. Following the below step to mapp the lead fields to Account object field while converting the lead records
  • Go>Setup>Customize>Lead>Fields
  • Then under the custom field section, click 'Lead Map fields' &then map the lead fields into account or contact object
Next time if you convert the lead records, then custom lead field value will be autopopulated to account record. 
NBP1411NBP1411
Thanks. I have tried that and it only allows me to map my custom field in Leads to other custom fields in Accounts. I have replicated the exact format that is in the SIC Code setting (Text- 20 characters) and nothing comes up. Any thoughts?
Gabriel KaneGabriel Kane
I have the same problem. Any answers?
ShafiShafi
trigger trigMapFields on Lead (before update)
{
    //map to hold convered lead's account Id as key with custom lead SIC as value
    map<id,string> convertedLeadSIC = new map<id,string>();
    //list to collect accounts to update
    list<account> acctList = new list<account>();

    for(Lead lead:System.Trigger.new)
    {
        if (lead.IsConverted)
        {
            convertedLeadSIC.put(lead.ConvertedAccountId,lead.SIC__c);
        }       
    }
    for(account acc : [SELECT Id,SIC FROM Account WHERE Account.Id IN : convertedLeadSIC.keyset()])
    {
        acc.SIC = convertedLeadSIC.get(acc.Id);
        acctList.add(acc);
    }
    update acctList;
    
}