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?



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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.