4

I have created flow + Process Builder to do a lookup relationship Count on parent object. My issues is I have a validation rule which fires when user try to deleted last child record from the related list. The validation rule is firing as an error. I don't know how to catch this error and display it in the page. There should not be any visualforce page is my requirement.

trigger JobApplicationTrigger on Job_Application__c (after delete) {
    try
    {
        for(Job_Application__c jobapp : Trigger.old)
        {
           Map<String, object> param= new Map<String,object>();
           param.put('getRecordID',jobapp.Id);
           param.put('varCandidateID',jobapp.Candidate__c);
           Flow.Interview.DeleteJobAppRec_flow flow = new Flow.Interview.DeleteJobAppRec_flow(param);
           flow.start();
        }
    }
    catch(DMLException err)
    {
      new Job_Application__c().addError('You got an Error :'+err);   
    }
}
0

I got a work around. I don't know is it a right approach but it solved my problem. I am checking the validation condition is before trigger if condition is not satisfied i am throwing an error using addError() method so that Flow is not executed.

| improve this answer | |

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.