0

Lead conversion into account,contact and opportunity using process builder its throw an exception "The record couldn’t be saved because it failed to trigger a flow. A flow trigger failed to execute the flow with version ID 30128000000FH3r.
Flow error messages:An unhandled fault has occurred in this flow An unhandled fault has occurred while processing the flow.
Please contact your system administrator for more information. Contact your administrator for help.
"

public class AutoConvertLeads
{
   @InvocableMethod
public static void LeadAssign(List<Id> LeadIds)
{
    LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
    System.debug('---MasterLabel--'+CLeadStatus.MasterLabel);

    List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
    for(id currentlead: LeadIds){
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(currentlead);                
            Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
            Leadconvert.setDoNotCreateOpportunity(TRUE);
            MassLeadconvert.add(Leadconvert);
    }

    if (!MassLeadconvert.isEmpty() && MassLeadconvert.size()>0) {
        List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
    }
}

}

enter image description here

enter image description here

  • Can you share screen shot of your process builder. Normally this error occurs if you're referring to some field of other object through look up in your process builder but there is no record for that object. In this case you need to add a null check for that object. – Rohit Mourya Apr 13 '17 at 11:59
  • @RohitMourya added screenshot – cloudZigZag Apr 13 '17 at 12:35
  • what is the entry criteria for your process builder. I mean whether it's a record created or record changes? – Rohit Mourya Apr 13 '17 at 12:38
0

Try this:

public class AutoConvertLeads
{

    @future
    public static void LeadAssignFuture(List<Id> LeadIds)
    {
        LeadStatus CLeadStatus= [SELECT Id, MasterLabel FROM LeadStatus WHERE IsConverted=true Limit 1];
        System.debug('---MasterLabel--'+CLeadStatus.MasterLabel);

        List<Database.LeadConvert> MassLeadconvert = new List<Database.LeadConvert>();
        for(id currentlead: LeadIds){
            Database.LeadConvert Leadconvert = new Database.LeadConvert();
            Leadconvert.setLeadId(currentlead);                
            Leadconvert.setConvertedStatus(CLeadStatus.MasterLabel);
            Leadconvert.setDoNotCreateOpportunity(TRUE);
            MassLeadconvert.add(Leadconvert);
        }

        if (!MassLeadconvert.isEmpty() && MassLeadconvert.size()>0) {
            List<Database.LeadConvertResult> lcr = Database.convertLead(MassLeadconvert);
        }
    }

    @InvocableMethod(label='Lead Conversion' Description='It Converts a Lead')
    public static void LeadAssign(List<Id> LeadIds)
    {
        LeadAssignFuture(LeadIds);
    }
}

This could happen because you are performing multiple DML operation at the same time like creating a Contact & Account Record.User future method to perform DML operation asynchronously.

Let me know if it helps.

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.