Skip to content

Instantly share code, notes, and snippets.

@waltonzt
Created February 8, 2018 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waltonzt/45bbb71a68a193233398bab0c4420dee to your computer and use it in GitHub Desktop.
Save waltonzt/45bbb71a68a193233398bab0c4420dee to your computer and use it in GitHub Desktop.
Sets the RO header status by looking at the Quanitites on the Lines.
List<inscor__Repair_Order__c> roToUpdate = new List<inscor__Repair_Order__c>();
for (inscor__Repair_Order__c ro : [SELECT Id, inscor__Status__c,
(SELECT Id, Name,inscor__Quantity_Received__c,inscor__Quantity_to_Repair__c,
inscor__Status__c
FROM inscor__Repair_Order_Lines__r)
FROM inscor__Repair_Order__c]) {
Boolean received = true;
Boolean inRepair = true;
Boolean sentTo = true;
for (inscor__Repair_Order_Line__c line : ro.inscor__Repair_Order_Lines__r) {
if (line.inscor__Quantity_to_Repair__c > line.inscor__Quantity_Received__c) {
received = false;
}
if (line.inscor__Quantity_Received__c == 0) {
inRepair = false;
}
if (line.inscor__Quantity_to_Repair__c == 0) {
sentTo = false;
}
}
if (received == true) {
ro.inscor__Status__c = 'Received - Complete';
} else if (inRepair == true) {
ro.inscor__Status__c = 'In Repair';
} else if (sentTo == true) {
ro.inscor__Status__c = 'In Progress';
}
roToUpdate.add(ro);
}
update roToUpdate;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment