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
BrittanieBrittanie 

trigger to convert lead with use of custom button (no opp default) rather then standard convert

I have a tigger that works great with a variety of settings and workflows to auto convert lead on approval BUT I want it to be done without creating the opportunity.  I have a custom button to convert without a opportunity but it has to be done mannually... How do I make my trigger use my custon Convert_No_Opp button!!

 

Any help would be great!

 

trigger ConvertLead on Lead (after insert, after update) {
for (Lead lead : Trigger.new) {
if ((lead.isConverted == false)&&(lead.Status == 'Assigned')&& (lead.Exclude_from_workflow__c == false)) //to prevent recursion 
{
 Database.LeadConvert lc = new Database.LeadConvert();
LeadStatus convertStatus = [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true LIMIT 1];
 lc.setConvertedStatus(convertStatus.MasterLabel);
 
 if (lead.Exclude_from_workflow__c == false){
 Database.LeadConvertResult lcr = Database.convertLead(lc);
System.assert(lcr.isSuccess());}
}
}
 }

 

JohnSchultzJohnSchultz

You should be able to just add the following line to your code:

 

lc.setDoNotCreateOpportunity(true);