I've got implemented code where I do automatic Lead conversion. The conversion works fine, but there are some custom validation rules in the org. When these validation rules fire, an ugly message is displayed to the user mentioning apex class/trigger and so on. I want to eliminate this message and instead use a more user-friendly one.
My code:
List<Database.LeadConvertResult> lcResults = new List<Database.LeadConvertResult>();
try {
lcResults = Database.convertLead(leadConverts, false);
for (Database.LeadConvertResult res : lcResults) {
if (!res.isSuccess()) {
//I will never get here --> every failed conversion is set as successful
}
}
} catch (Exception e) {
//I will never get here --> even though the conversion fails with DmlException,
//I am not able to catch this exception (not with DmlException, not with general Exception)
}
Exception I am getting:
System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION
Any idea what am I doing wrong here? I really don't know what else should I try.
allOrNothing = false
, the try-catch is not applicable