I have two objects, Revenue Schedule and revenue schedule split. Every Revenue Schedule will have 3 revenue schedule split records. For Revenue Schedule object I have 3 fields: sales rep 1, sales rep 2, and sales rep 3.
But I have only one field for Revenue schedule split object which is sales rep. Now on updating revenue schedule I want to update split records. Below is my code -
if(trigger.IsUpdate){
for(Revenue_Schedule__c shed: Trigger.new){
Double percentRemain = 100.0;
percentRemain -= (Double) shed.Split_Percent_2__c;
percentRemain -= (Double) shed.Split_Percent_3__c;
for(Rev_Schedule_Split__c sp: revshedtoSplits.get(shed.id)){
//split 1 calculation
if(shed.Sales_Rep_1__c != null){
sp.Sales_Rep__c = shed.Sales_Rep_1__c;
sp.Amount_LC__c = percentRemain * shed.Revenue_LC__c * .01;
sp.Amount_USD__c = percentRemain * shed.Revenue_USD__c * .01;
}
//split 2 calculation
if(shed.Sales_Rep_2__c != null){
sp.Sales_Rep__c = shed.Sales_Rep_2__c;
sp.Amount_LC__c = shed.Split_Percent_2__c * shed.Revenue_LC__c * .01;
sp.Amount_USD__c = shed.Split_Percent_2__c * shed.Revenue_USD__c * .01;
}
//split 3 calculation
if(shed.Sales_Rep_3__c != null){
sp.Sales_Rep__c = shed.Sales_Rep_3__c;
sp.Amount_LC__c = shed.Split_Percent_3__c * shed.Revenue_LC__c * .01;
sp.Amount_USD__c = shed.Split_Percent_3__c * shed.Revenue_USD__c * .01;
}
toUpdatesplits.add(sp);
}
}
if(toUpdatesplits != null && toUpdatesplits.size()>0){
update toUpdatesplits;
}
}
where revshedtoSplits is a map which stores Revenue Schedule id and corresponding split records. Above code is updating the split records with the sales_rep_3 for all split records. I want to update each split record by sales rep 1,2 and 3. I tried using break statement, but it is breaking from for loop itself. I just want to break from if loop. Please guide.