I have this Approval Scenario where I want to have this feature where :
If one user presses the "submits for approval" button on the Account record, the approval process will go to 5 users to ask for their approval. Only if AT LEAST 2 of the 5 approvers approve then the Account will be Finally Approved.
As in the picture above, I want a radio button to have an option to 'approve based on the first n response' (n meaning any number).
Is there a simple way around this using OOTB way, apex, apex trigger or any other ways?
** UPDATE **
Here is my attempt of using Apex Trigger to count the number of "Status = Approved" from the Approval History related list of Account (My SOQL doesnt seem to work):
trigger ApprovalHistoryCountTrigger on ProcessInstance (after insert, after update, after delete, after undelete) {
Map<Id,List<ProcessInstance>> originalFileIds = new Map<Id,List<ProcessInstance>>();
Set<id> fileIds = new Set<id>();
if (Trigger.new <> null){
for(ProcessInstance c:Trigger.new){
if(c.TargetObjectId != null)
fileIds.add(c.TargetObjectId);
}
} else if(Trigger.old != null){
for(ProcessInstance c:Trigger.old){
if(c.TargetObjectId <> null)
fileIds.add(Trigger.oldMap.get(c.id).TargetObjectId);
}
}
if (fileIds.size() > 0){
try{
List<ProcessInstance> cdlList = new List<ProcessInstance>();
Map<id,Account> testmap = new Map<id,Account>(
[select id, Count_AA_Approvals__c from Account where id IN: fileIds]);
cdlList = [SELECT id, TargetObjectId
FROM ProcessInstance
WHERE TargetObjectId IN:fileIds
AND ID in (SELECT ProcessInstanceId FROM ProcessInstanceSteps WHERE StepStatus = "Approved")
AND ID in (SELECT ProcessInstanceId FROM ProcessInstanceNode WHERE DeveloperName = "AA_to_Approve") ];
for (ProcessInstance cdl : cdlList){
List<ProcessInstance> cdlList2 = new List<ProcessInstance>();
if (originalFileIds.get(cdl.TargetObjectId ) == null){
cdlList2 = new List<ProcessInstance>();
cdlList2.add(cdl);
originalFileIds.put(cdl.TargetObjectId, cdlList2);
}
/* else if(originalFileIds.get(cdl.TargetObjectId) != null){
cdlList2 = new List<ProcessInstance>();
cdlList2 = originalFileIds.get(cdl.TargetObjectId);
cdlList2.add(cdl);
originalFileIds.put(cdl.TargetObjectId, cdlList2);
}
*/
}
for (Id i: fileIds){
//If have 1 or more attachments
if (testmap.get(i) != null && originalFileIds.get(i) != null){
testmap.get(i).Count_AA_Approvals__c = originalFileIds.get(i).size();
//If have no attachments
} else if (testmap.get(i) != null && originalFileIds.get(i) == null){
testmap.get(i).Count_AA_Approvals__c = 0;
}
}
update testmap.values();
System.Debug(testmap.values());
} catch(Exception e){}
}
}