Need help to modify a trigger to update the Case status if Order status changes. below trigger is working but seems if for only one Order status change. need to modify the trigger if ALL Order records related to Case have status changed, then Case status updated . thanks
trigger OrderTrigger on Order (after insert, after update, after delete) {
public String currentCaseId {get;set;}
List<Order> OrderList = new List<Order>();
for (Order Ord:trigger.new) {
OrderList.add(Ord);
currentCaseId=Ord.Case__c;
}
List<Case> CaseList = new List<Case>([select Id,Status from Case where Id = :currentCaseId]);
String caseApproved = 'Approved';
String caseCompleted = 'Completed';
String caseInvalid = 'Invalid';
String caseRejected = 'Rejected';
String caseNew = 'New';
String caseIncomplete = 'Incomplete';
String caseInProgress = 'In-Progress';
for (Order currentOrd: OrderList) {
for (Case ordCase: CaseList) {
if(currentOrd.Status == caseApproved) {
ordCase.Status = caseCompleted;
}
if(currentOrd.Status == caseInvalid) {
ordCase.Status = caseRejected;
}
if(currentOrd.Status == caseNew || currentOrd.Status == caseIncomplete) {
ordCase.Status = caseInProgress;
}
}
}
update CaseList;
}