I'm new to developing and need help with the following code. When the status on valuation changes from active to inactive, VL__Active_Valuation__c on monitoring should be cleared out. I already got it working on shareholder but it doesn't work for monitoring. Could someone help me out on this one? Here's the code:
public static void deactivateValuation(List<VL__Valuation__c> valuations){
Set<Id> shareholderIds = new set<Id>();
for(VL__Valuation__c valuation: valuations){
shareholderIds.add(valuation.VL__Shareholder__c);
}
Map<Id, VL__Shareholder__c> shareholders = new Map<Id,VL__Shareholder__c>([SELECT VL__Active_Valuation__c FROM VL__Shareholder__c WHERE Id IN: shareholderIds]);
Map<Id, VL__Investment_Monitoring__c> monitorings = new Map<Id, VL__Investment_Monitoring__c>([SELECT VL__Active_Valuation__c FROM VL__Investment_Monitoring__c WHERE VL__Shareholder__c IN: shareholderIds]);
for(VL__Shareholder__c shareholder : shareholders.values()){
for(VL__Valuation__c valuation: valuations){
if(shareholder.VL__Active_Valuation__c == valuation.Id){
shareholder.VL__Active_Valuation__c = null;
}
}
}
for(VL__Investment_Monitoring__c monitoring : monitorings.values()){
for(VL__Valuation__c valuation: valuations){
if(monitoring.VL__Active_Valuation__c == valuation.Id){
monitoring.VL__Active_Valuation__c = null;
}
}
}
update shareholders.values();
update monitorings.values();
}