Find your content:

Search form

You are here

Convert lead through apex but should not create opportunity


I am doing a lead conversion thorugh apex. When the lead is converted it should only create account and contact and should not create opportunity.

There are a few other items that i need to capture on the Lead conversion page. To do this i am having a new VF page to override the standard conversion page.

On the standard Lead conversion page we have checkbox to prevent the opportunities to get created. I need to incorporate the same functionality in VF page.

I could figure out on the standard conversion page if we add nooppti=1 to the url would check the checkbox for Do not create opportunity


Couldnt find anything on how to do it through apex. Any ideas?


Attribution to: Prady

Possible Suggestion/Solution #1

Take a look at the ConvertLead Operation. Specifically, the setDoNotCreateOpportunity method. Below is an example of how to convert a lead within Apex, without creating an opportunity.

public class LeadClass{
    public static void doConvert(Id leadId){

        Database.LeadConvert lc = new database.LeadConvert();
        lc.setDoNotCreateOpportunity(True); //**IMPORTANT METHOD HERE**

        LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
        Database.LeadConvertResult lcr = Database.convertLead(lc);

Attribution to: Mikey
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content