What is this error is about on Approval process? - Answers - Salesforce Trailblazer Community
Ask Search:
Tvvsn Surya NTvvsn Surya N 

What is this error is about on Approval process?

I have a trigger on 'Quote' (after insert ,after update)object.and i am getting this error. how to solve this. is this a permission access issue or what?

Error:Validation Errors While Saving Record(s)
There were custom validation error(s) encountered while saving the affected record(s). The first validation error encountered was "Apex trigger QuoteSubmitForApproval caused an unexpected exception, contact your administrator: QuoteSubmitForApproval: execution of AfterUpdate caused by: System.DmlException: Process failed. First exception on row 0; first error: NO_APPLICABLE_PROCESS, No applicable approval process was found.: []: Trigger.QuoteSubmitForApproval: line 170, column 1". 

*170thLine in the code is where i underlined  below. 

 if((q.Total_Selling_Price_Formula__c > 1000000 && (q.Business__c =='Petrochemical' || q.Business__c =='Refining') || q.Total_Selling_Price_Formula__c > 500000 && q.Business__c =='SA&S') && q.Standard_Proposal__c=='Yes' && q.Status=='Approved' && q.oppReCountQuoteProReCout__c==true && q.SEA_Status__c == 'Draft'){
                // create the new approval request for SEA Approval process
                Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();   
                req.setComments('Submitted for approval. Please approve.');
                Approval.ProcessResult resultList = Approval.Process(req); 
                Pinstance = [SELECT Id,TargetObjectId,Status FROM ProcessInstance where Status = 'Pending' AND TargetObjectId = :q.id];

Best Answer chosen by Tvvsn Surya N
Amnon KruviAmnon Kruvi

Your code right now is trying to send a quote for approval without having an approval process whose criteria it meets. You'll need to do one of two things:

1. Don't send the quote for approval in those cases where it shouldn't be (meaning: there is no approval process that can handle it).
2. Change your approval processes so that there is one for every possible scenario.

Which one you need to go with is a business decision - I'm afraid I can't help you choose :)