function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rahul Bhattad 4Rahul Bhattad 4 

How to write logic for multiple conditions to have dynamic process


We have two objects in our org Custom1__c and Approver__c which are linked via junction object Approval__c. I have a vf page where I show approvers by stages by comparing Sales Price and Margin coming from Custom1 object against the approver records stored in Appover object and then I store the records in Approval object on click of Save button which is linked with Approver and Custom1. So I am basically inserting records in Approval object which are linked to respective Custom1 and Approver record.

There can be multiple stages of Approvers and each stage can have 1 or 2 Approvers depending on the country which I am managing on VF page through controller class. 

When the records are inserted in Approval object, I have a trigger written on Approval (After Insert) which calls a future callout class and sends detail of Approval records of stage 1 and related Custom1 and Approver info to webservice.

Now I want to build a logic in trigger on Approval Object(after update), which checks the the status(field on Approval) of previous stage approval record(s) and if they are Approved then call the future callout class with details of Approval records of next stage and if the last stage is approved then update the Custom1 record's Status field to Active . I am really struggling to build a dynamic logic which will do this no matter how many Approvers are there in a particular stage and how many no of stages are there.

I know this might sound confusing to many readers and I can answer any questions or doubts. Any help will be really appreciated.

Thanks in Advance!
Derrick AbbeyDerrick Abbey
Hi Rahul,

How are the stages for any approval determined?