Created
February 8, 2018 22:04
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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