function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Natasha AliNatasha Ali 

How do I get my 'autoconvert' trigger to not create new opportunities when it auto converts a lead into a person account?

Hi,
So this trigger autoconverts a lead into a person account when they come in without the company field populated, and becuase it gets conceted into aperson account, it creates a contact & account & opportunity. We don't want it to create an opportunity, so how would I go about doing this with my trigger? or would I have to create a new one? 
Trigger AutoConvert on Lead (after insert) {
     LeadStatus convertStatus = [
          select MasterLabel
          from LeadStatus
          where IsConverted = true
          limit 1
     ];
     List<Database.LeadConvert> leadConverts = new List<Database.LeadConvert>();

     for (Lead lead: Trigger.new) {
          if (!lead.isConverted && lead.Company == null) {
               Database.LeadConvert lc = new Database.LeadConvert();
               String oppName = lead.Name;
               
               lc.setLeadId(lead.Id);
               lc.setOpportunityName(oppName);
               lc.setConvertedStatus(convertStatus.MasterLabel);
               
               leadConverts.add(lc);
          }
     }

     if (!leadConverts.isEmpty()) {
          List<Database.LeadConvertResult> lcr = Database.convertLead(leadConverts);
     }
}

Any help is much appreciated!!!

Many Thanks :)
Natasha
Paul S.Paul S.
Natasha - I've never worked with the LeadConvert class, but per the documentation here (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_dml_convertLead.htm), it looks like you can use the setDoNotCreateOpportunity method. 

Replace:
lc.setOpportunityName(oppName);
With: 
lc.setDoNotCreateOpportunity(true);