I have 4 record types, 3 (Service, Access and Equipment orders) are child, and the parent is (customer Orders)
When a date is updated in one of the child obejcts, I would like that date to be updated in the parents record as well.
E.g: If a order date changes in a order (child) then I would like this date to be displayed in the parent (Customer)
Also as they are all under one brunch object it will require mapping, how will I do this?
This is what I have so far:
trigger updateCaseDate on Case(before update){
Set<Id> setParentId=new Set<Id>();
List<Case> lstCaseUpdate=new List<Case>();
for(Case cs: Trigger.New){
if(cs.ParentId!=null && cs.Datetime_Required__c!=Trigger.OldMap.get(cs.Id).Datetime_Required__c){
setParentId.add(cs.ParentId);
}
}
if(setParentId.ISEMPTY()) return;
Map<Id, Case> mapCaseDetails=new Map<Id, Case>([Select Id, RFS_Date__c,Access_Install_Date__c,Equipment_Install_Date__c from Case where Id IN: setParentId limit 10000]);
for(Case cs: Trigger.New){
if(cs.ParentId!=null){
if(Recordtype='Service_Order'){
mapCaseDetails.get(cs.ParentId).RFS_Date__c=Date.Valueof(cs.Datetime_Required__c);
lstCaseUpdate.add(mapCaseDetails.get(cs.ParentId));
}
}
}
if(lstCaseUpdate.size()>0){
update lstCaseUpdate;
}