Here's the trigger I created to update a list of service orders related to a Case when a field is changed in that particular Case. System.debug shows the Order Status value set to 'Closed' but it is not updating in the Service_Order object. Am I missing any important detail?
trigger InvoiceTriggerfromCase on Case (after update){
Case CS = Trigger.New[0];
Case oldCS = Trigger.oldMap.get(CS.ID);
if(newCS.Invoice_Number__c != oldCS.Invoice_Number__c ){
List<Service_Order__c> listWO = [Select Order_Status__c from Service_Order__c
where Case__r.CaseNumber = :CS.CaseNumber];
for(Service_Order__c wo : listWO) {
if(wo.Order_Status__c != 'Closed'){
wo.Order_Status__c = 'Closed' ;
}
}
update listWO;
System.Debug(listWO[0].Order_Status__c );
System.Debug(listWO[1].Order_Status__c );
} }