0

When selecting the status of "Converted" in a Lead, the message at the top is displayed:

enter image description here

And the Lead is not converted, it is necessary to press the "Convert" button and perform the conversion.

Is it possible to configure the Lead to be converted as soon as it is changed to this status, using some configuration or apex class, or is it mandatory to click the button always?

1
  • You can do it by means of Apex for sure but it is not clear what you are looking to convert the Lead to?
    – TSmith
    Commented May 10, 2021 at 15:52

1 Answer 1

1

You can use a trigger to convert the Lead when the status is set to converted. You can tweak the code to suit your business needs.

List<Database.LeadConvert> listToConvert = new List<Database.LeadConvert>();
LeadStatus convertStatus = [SELECT Id, MasterLabel, IsConverted FROM LeadStatus WHERE IsConverted=true limit 1];
for(Lead leadObj: trigger.New){
    //Either this or you can check the old map to verify the leads where the status has changed
    if(leadObj.Status == 'Converted' && !leadObj.isConverted){
        Database.LeadConvert lc = new Database.LeadConvert();
        lc.setConvertedStatus(convertStatus.MasterLabel);
        lc.setLeadId(leadObj.Id);
        //lc.setAccountId(); If you want to map the converted lead to an existing account
        //lc.setContactId();
        //lc.setDoNotCreateOpportunity(true); //Or False
        listToConvert.add(lc);
    }
}
try{
    List<Database.LeadConvertResult> lcResults = Database.convertLead(listToConvert);
}Catch(Exception exp){
    //Handle exception
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .