There is a need for a custom approval process at my company and I'm stuck on how to create this trigger.
I have a parent object called Bids with a child object related called Approvals. I want to update the status field (status_c) on the Bids object, when ALL of the Approvals that have a type of "Bid" change their status to "Foward", and change the Bid.Status_c to another value when ALL of the Approvals of a different type have a status of "Forward"
How would I do this with a trigger. I'm very new to Apex development but welcome any help.
I created this trigger but instead of updating the parent (Bid) when ALL of the child records (Approvals) have been updated based on certain criteria, it updates the parent every time ANY of the child records has been updated based on the criteria.
trigger ConcatenateFields on Approval__c(after insert,after update){
List<Bid__c> parentObjList = new List<Bid__c>();
public List<Id> listIds = new List<Id>();
for(Approval__c childObj : Trigger.new){
listIds.add(childObj.Bid__c);
}
parentObjList = [SELECT id,Name,(SELECT ID, status__c, type__c
FROM Approvals__r)
FROM Bid__c
WHERE ID IN :listIds];
for (Bid__c bid : parentObjList){
for(Approval__c bsaa: bid.Approvals__r) {
if(bsaa.Status__c =='Forward' && bsaa.type__c == 'Contract') {
bid.Status__c='Approved';
}
if(bsaa.Status__c =='Forward' && bsaa.type__c == 'RFQ') {
bid.Status__c='Approved';
}
}
}
update parentObjList;
}