0

I built a record triggered flow to launch an invocable Apex class that auto converts leads. The problem is their are several validation rules on the lead object so whenever a user converts a lead that violates one of the validation rules instead of getting a useful error from the validation rule they get a confusing message saying that the flow failed which is confusing them.

To get around this I want to create a screen flow that launches the Apex with a fault path from the Apex action but I'm having trouble finding documentation on how to do this. Any advise?

Specifically how should I launch the process? Should I use a quick action to launch the flow on the convert button? Also, is there a way to modify the fault path so I can include a message specific to the validation rule they are violating?

enter image description here

Here is a picture of what I have so far.

Thank you!

1 Answer 1

2

In my opinion, you're going about this the wrong way. You can simply return a value to the flow to determine the path:

public class Request {
  @InvocableVariable(required=true) public Lead record;
}
public class Result {
  @InvocableVariable public Boolean success;
  @InvocableVariable public String message;
}
@InvocableMethod(label='Auto Convert Leads')
public static Result[] autoConvertLeads(Request[] requests) {
  Result[] results = new Result[0];
  Lead[] leadsToConvert = new Lead[0];
  for(Request request: requests) {
    leadsToConvert.add(request.record);
  }
  // I'm abstracting this away here
  Database.LeadConvert[] converts = setupLeadConverts(leadsToConvert);
  // Allow partial success here
  Database.LeadConvertResult[] convertResults = Database.convertLeads(converts, false);
  for(Database.LeadConvertResult leadConvertResult: convertResults) {
    Result res = new Result();
    res.success = leadConvertResult.isSuccess();
    if(!res.success) {
      res.message = res.getErrors()[0].getMessage();
    }
    results.add(res);
  }
  return results;
}

You'd then get rid of the fault screen, and instead use a Decision Element to show the error when success is false, and the final screen when success is true.

You must log in to answer this question.

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