How To

Assign a Specific Opportunity Record Type During Lead Conversion

LeadConversion

If an opportunity is created during the lead conversion process, Salesforce will create the opportunity record associated to the default opportunity record type associated to the user’s profile. This is perfectly fine if there is only one opportunity record type for the user. However, this becomes a problem when a user has multiple opportunity record types and the default does not apply in all cases.

We will address this with a workaround declaratively by assigning a specific opportunity record type upon lead conversion.

Here are a few lessons learned from implementing this use case:

  • Do not “hardcode” IDs in process builder. If you need to update IDs to make them environment specific, do it outside process builder so you don’t run the situation where you have different versions of the same process builder in different environments. 
  • Create a custom formula field on the lead object to determine the opportunity record type ID custom label for a given lead record type. Note: This can also be accomplished using custom settings, but custom settings get wiped out with each refresh so you need to put the custom setting record back into the environment. It is too bad that you can’t reference custom metadata type in a formula. That would’ve been my preference. LOVE, LOVE custom metadata types!
  • Use process builder to update the opportunity record type when a lead with a specific record type is converted.
  • Provide descriptions, where provided, in Salesforce. This may be tedious step, I know, but your future self will thank you when you are trying to remember what you configured or assist other/future admins when troubleshooting or enhancing what was built. This includes noting the data stored in a custom field, providing the purpose of a process builder, etc.

 

Business Use Case: Addison Dogster is a system administrator at Universal Container. Sally Sunshine is the Sales Manager. There are two lead processes and two sales processes at Universal Container. When a lead is associated to the Lead 1 process, upon lead conversion, the opportunity created is associated to the Sales 1 process. When a lead is associated to the Lead 2 process, upon lead conversion, the opportunity created is associated to the Sales 2 process. Sally noticed when a lead is converted, regardless of the lead record type, the opportunity record created was always associated to the user’s default opportunity record type. This required an additional manual step to change the opportunity record type for certain converted leads.

Solution: Being the Awesome Admin that she is, Addison is able to solve this declaratively using custom formula field to determine the opportunity record type ID, custom labels to store the opportunity record type IDs (no hardcoding!) and process builder* to update the opportunity record’s opportunity record type upon lead conversion. All of this is done with clicks, not code. Hooray!

*Note: This can also be solved using a workflow rule. One of the reasons, I lean towards solutioning this with process builder instead is that process builder continues to be enhanced and I can further enhance process builder for additional processes that need to run on the Lead object and manage it in one place. For those who use workflow rules, if your Salesforce org has many workflow rules, it can become unruly to manage/troubleshoot. Additionally, Salesforce recommends you start with process builder for automating your processes.

Quick Steps:

Assumptions: The lead (Lead1 and Lead2) and opportunity (Opp1 and Opp2) records types, lead processes (Lead1 and Lead2) and sales processes (Opp1 and Opp2) already exist in the system. We will not cover the steps of creating those in this blog post.

  1. Create two custom labels called “Opp1_Record_Type” and “Opp2_Record_Type” under Setup | Create | Custom Labels in Salesforce Classic or Platform Tools | User Interface | Custom Labels in Lightning Experience.  

Use the Opportunity Record Type’s SFDC 18 character ID in the value field. Navigate to the opportunity record type’s record in setup. In the URL, copy the 15 character ID (highlighted in yellow).

Lead1RecordType.JPG

Go to this conversion tool: https://www.adminbooster.com/tool/15to18. Enter the SFDC 15 character ID in the left box, click the 15=>18 button and copy the resulting value (18 character ID) in the right box into the value field of the custom label.

15to18Conversion.JPG

Repeat this for each Opportunity record type.

The end result looks like this…OpportunityRecordType-CustomLabels.JPG

2. Create a custom formula text field called “Opp Record Type” to the Lead object. For those using Salesforce Classic, you can create custom fields by going to Setup | Customize | Lead, click the New button under Custom Fields or Platform Tools | Object Manager | Lead, click on the New button under Fields & Relationships in Lightning Experience.

Here we will write a formula based on the Lead’s record type, pull in the appropriate Opportunity Record Type custom label. The syntax below says if the Record Type’s Developer name is “Lead1”, then use the custom label “Opp1_Record_Type”. Otherwise, use the custom label “Opp2_Record Type.”

Formula: IF(RecordType.DeveloperName=”Lead1″, $Label.Opp1_Record_Type, $Label.Opp2_Record_Type)

The end results looks like this…OppRecordTypeCustomField.JPG

Best practice tips:

  • Don’t forget to provide a description so you and other/future admins know what this custom field is used for.
  • Leave this field off the page layouts since this is a processing field. By default, new fields are added to the page layout.

3. Now, let’s create the process builder, click the New button.

ProcessBuilder-NeworUpdatestoExistingLeads.JPG

We are going to call this generically “New or Updates to Existing Leads” so that we can add new processes in the future.

ProcessBuilder-NeworUpdatestoExistingLeads-Properties.JPG

For those using Salesforce Classic, permission set can be found in Create | Workflows & Approvals | Process Builder. In Lightning Experience, it is found under Process Automation | Process Builder.

Best practice tips: Don’t forget to provide a description so you and other/future admins know what this process builder is used for.

A. Select “Lead” as the object. Select to start the process “when a record is created or edited” and click the “Save” button.

ProcessBuilder-NeworUpdatestoExistingLeads-LeadObject.JPG

B. Let’s set the first criteria node. We will call it “Lead Conversion – Lead2.” We want this to execute when the lead is converted AND the Lead Record Type Developer Name is “Lead2.” 

Set the Criteria for Executing Actions to “Conditions are met”

[Lead].IsConverted Equals Boolean True

[Lead].RecordType.DeveloperName Equals String Lead2

Note: We lead with the [Lead].IsConverted criteria in the formula first so that if that is not true, Salesforce will not continue to look at the record type.

The end results looks like this…

ProcessBuilder-NeworUpdatestoExistingLeads-FirstCriteriaNode.JPGAs an immediate action, we will update the related opportunity record.

Select “Update Records” as the Action Type

Let’s call the Action Name as “Update Record Type ID”

For the Record Type, select “Select a record related to the Lead”, locate the Converted Opportunity ID and click on the Choose button.

ProcessBuilder-NeworUpdatestoExistingLeads-SelectRelatedRecord.JPG

Set “No criteria—just update the records!” under Criteria for Updating Records

Now, set the Record Type ID, using a formula to “[Lead].Opp_Record_Type__c”

End result…

ProcessBuilder-NeworUpdatestoExistingLeads-FirstCriteriaNode-ImmediateAction.JPG

C. Let’s set the second criteria node. We will call it “Lead Conversion – Lead2.” It’s going to pretty similar to the first criteria node and its immediate action.

Here’s the criteria node:

[Lead].IsConverted Equals Boolean True

[Lead]RecordType.DeveloperName Equals String Lead1

ProcessBuilder-NeworUpdatestoExistingLeads-SecondCriteriaNode.JPG

Here’s the immediate action:

ProcessBuilder-NeworUpdatestoExistingLeads-SecondCriteriaNode-ImmediateAction.JPG

D. Now, click on the Stop button for the first criteria node and change it to “Evaluate the Next Criteria (Summer 16 enhancement) and click the Save button.

ProcessBuilder-NeworUpdatestoExistingLeads-EvaluateNextCriteria.JPG

E. Click on the Activate button to activate the process builder.

ProcessBuilder-NeworUpdatestoExistingLeads-Activate.JPG

That’s it! Congrats! You’ve implemented a process to update the opportunity record type upon lead conversion based on the lead record type.

Now, before you deploy the changes to Production, you need to test your configuration changes.

1. Login as a user and create a new lead with the Lead1 record type. Convert the lead.

a.Confirm that the opportunity created has the Opp1 record type.

2. Create a new lead with the Lead2 record type. Convert the lead.

a. Confirm that the opportunity created has the Opp2 record type.

Deployment Notes/Tips:

  • The new custom field, custom labels and process builder can be deployed to Production in a change set (or can be deployed using a tool such as Dreamfactory’s Snapshot).
  • Update the values of the custom labels with the Production opportunity record types if they are not the same in the sandbox.
  • Activate process builder as it is deployed as inactive into Production.
Advertisements

2 thoughts on “Assign a Specific Opportunity Record Type During Lead Conversion

  1. Thanks, Other way around I was thinking is to create a custom picklist in both Leads & Ops and map each other. Then have a workflow field update on the opp to update the record type on creation based on that.

    field name: Process and picklist values: B2B,B2C,B2E.
    so if my default Op record type is B2B, when i convert the lead and the Process field is B2E the workflow updates the Op record type

    Isn’t this more simple?

    Oscar

    Like

  2. The formula determines the opp type based on the lead record type and the process builder updates the opp once the lead is converted. While workflow rules can handle the situation, the idea is to use process builder because workflow rules are no longer enhanced and you can visually manage all your processes in one place in process builder versus the nightmare of a long list of WF rules in an org as it grows over time.

    Like

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s