Forcing Opportunity Creation During the Lead Conversion Trigger | Techila
single,single-post,postid-1144,single-format-standard,ajax_updown_fade,page_not_loaded,,qode_grid_1300,footer_responsive_adv,hide_top_bar_on_mobile_header,qode-content-sidebar-responsive,qode-theme-ver-9.4.2,bridge,wpb-js-composer js-comp-ver-4.12,vc_responsive

Forcing Opportunity Creation During the Lead Conversion Trigger

Forcing Opportunity Creation During the Lead Conversion Trigger

Lead Conversion is a process in Sales Cloud that helps users convert leads into related accounts and open new opportunities. This is useful in preventing rework of transferring data from lead fields to Account fields. The entire process of Copy Paste is done with a single touch of button and the data is transferred.

However, on business end, the customer has just closed the deal and now the company has earned an Account Salesforce allows you to streamline the business processes by field mapping.

We can map custom fields on Lead object to Custom Fields on Contact, Opportunity or Account object using field mapping on Lead setup.

However, there are times when we need to extend the standard the Convert functionality for a more complex purposes for e.g.,
1. Transferring some related object from lead to Account, Opportunity or Contact.
2. Throwing an Error if the Opportunity is not created on Conversation

In this example I am going to create a trigger that throws an error if the Create Opportunity check-box is not checked.

For Example: Throw an error that opportunity is not created.
Apex Code:

trigger CheckOpportunityOnLeadConvert on Lead (after update) {
 //Check if the trigger is run from UI only.
  if ( == 1) {
     if (Trigger.old[0].isConverted == false &&[0].isConverted == true) {
      // Check if if a new opportunity was created
      if ([0].ConvertedOpportunityId == null) {
          //Throw an error
 [0].addError('Please create an opportunity');


Description: ForcingOpportunityCreatingDuringtheLeadConversionTrigger-1.png

The error is thrown on the Conversation, preventing it from moving on. The trigger is not that complicated but is a good start to recreate.


Author: techila

No Comments

Post A Comment