Back in 2014 there was no Process Builder, so our only options for assigning record types on lead conversion were Workflow Rules and Field Updates or Apex Triggers, like this one. Since then, Salesforce released in Winter '16 Process Builder that lets us solve this problem with clicks-not-code. The code is here if you'd like to use it, but for new folks I recommend checking out my blog post on Advanced Lead Conversion Using Process Builder.
As of this writing, the Salesforce Lead Conversion process does not allow users to pick the record types for the converted accounts/contacts/opportunities.
Salesforce instead uses the 'default' record type for those objects of the user's profile who is performing the conversion. This assumption is not always valid, particularly for users that have multiple record types available to them or that the ones they use aren't actually flagged as 'default' on their profile (for example, the user's profile has the master record type as default but the record types they actually use are granted through permission sets).
This trigger is a workaround that leverages a custom setting to provide administrators a way to provide simple one-to-one record type conversion mappings while still using the out-of-the-box lead conversion page.
Simply put, this trigger looks up a xref from the custom setting based on the lead's record type then for each converted object (account, contact, opportunity) it updates their record types to the values specified in the custom setting.
On the Salesforce Success Community, the ability to choose a record type is a highly requested feature, and I hope that this workaround will eventually not be necessary:
- https://success.salesforce.com/ideaView?id=08730000000Bra8AAC
- https://success.salesforce.com/answers?id=90630000000gvCcAAI
- https://success.salesforce.com/0D53000001bwU9T
Read the Salesforce Docs on Lead Conversion Process to learn more:
Before attempting to deploy these customizations, please ensure that custom record types exist for Account, Contact, Lead, and Opportunity objects. In my unscientific testing, the recordTypeId
field on sobjects
is not available unless custom record types exist, which will cause the apex tests to fail during deployment. This is a common "gotcha" when deploying this into new orgs. First reported by @rsmithdev6.
To implement this workaround in your salesforce org you will need to create a custom setting and deploy the apex classes in this repository. The steps are very easy to do, and I'll outline the basic steps below.
- Create a Custom Setting
- Create an Apex Class
- Create an Apex Trigger
- Create an Apex Test
The custom setting is our cross-reference mapping between Lead record types and Account, Contact, and Opportunity record types that we want to leverage during lead conversion process.
Once the custom setting is defined, from its detail page click the Manage button to add some mappings. You will create a new instance of the custom setting for each of your Lead record types. The name field of the custom setting will hold our Lead record type names and the three fields on the custom setting will hold the names of the actual record types we want to use for those sobjects during lead conversion. If you don't use Opportunities then that field can be left blank. It is only used by the code if the lead converted into an opp.
- Easily deploy this customization to your org with the GitHub Salesforce Deploy Tool authored by Andy Fawcett
- Configure the Custom Setting as described above with appropriate lead, account, contact, and opportunity record types