You need to sign in to do that
Don't have an account?
ethan hunt
Avoid instantiating new objects inside loops
Hi,
I am getting the following rule exception on the below line of code. Please suggest what can be the alternative for this -
Opportunity updateOpportunity;
List<Opportunity> listToUpdateMasterOpportunity = new List<Opportunity>();
for(Opportunity opp : updateMasterOpportunity) {
updateOpportunity = new Opportunity(id = opp.id); ////////////Avoid instantiating new objects inside loops
if(mapCalculatedMasterOptyVal.get(opp.id) != null) {
updateOpportunity.Sub_Opportunities_Total_Amounts__c = mapCalculatedMasterOptyVal.get(opp.id);
}
listToUpdateMasterOpportunity.add(updateOpportunity);
}
opportunityDao.updateOpportunity(listToUpdateMasterOpportunity);
}
I am getting the following rule exception on the below line of code. Please suggest what can be the alternative for this -
Opportunity updateOpportunity;
List<Opportunity> listToUpdateMasterOpportunity = new List<Opportunity>();
for(Opportunity opp : updateMasterOpportunity) {
updateOpportunity = new Opportunity(id = opp.id); ////////////Avoid instantiating new objects inside loops
if(mapCalculatedMasterOptyVal.get(opp.id) != null) {
updateOpportunity.Sub_Opportunities_Total_Amounts__c = mapCalculatedMasterOptyVal.get(opp.id);
}
listToUpdateMasterOpportunity.add(updateOpportunity);
}
opportunityDao.updateOpportunity(listToUpdateMasterOpportunity);
}
List<Opportunity> listToUpdateMasterOpportunity = new List<Opportunity>();
for(Opportunity opp : updateMasterOpportunity) {
if(mapCalculatedMasterOptyVal.get(opp.id) != null) {
opp.Sub_Opportunities_Total_Amounts__c = mapCalculatedMasterOptyVal.get(opp.id);
}
listToUpdateMasterOpportunity.add(opp);
}
opportunityDao.updateOpportunity(listToUpdateMasterOpportunity);
}