You need to sign in to do that
Don't have an account?

object instatiation exception
Hi ,
I am getting Avoid instantiating new objects inside loops in the below line. Can this be avoided.Please suggext
Map<Id, Opportunity> mapOpportunityOwnerId;
List<OpportunityTeamMember> listOpportunityTeamMember;
if(setOpportunityId != null) {
// get the map of Opportunity Id and it's corresponding owner Id
mapOpportunityOwnerId = queryDMLHelper.getOpportunity(setOpportunityId);
// get the list of Opportunity team members for a set of Opportunities
listOpportunityTeamMember = queryDMLHelper.getListOpportunityTeam(setOpportunityId);
}
Map<Id, Set<Id>> mapOpportunitySalesTeamId = new Map<Id, Set<Id>>();
if(listOpportunityTeamMember != null) {
for(OpportunityTeamMember salesTeamMember : listOpportunityTeamMember) {
setSalesTeamId = new Set<Id>(); ///////////////////////////////////Avoid instantiating new objects inside loops
if(mapOpportunitySalesTeamId.get((Id)salesTeamMember.get('OpportunityId'))== null) {
setSalesTeamId.add((Id)salesTeamMember.get('UserId'));
mapOpportunitySalesTeamId.put((Id)salesTeamMember.get('OpportunityId'), setSalesTeamId);
}
else {
mapOpportunitySalesTeamId.get((Id)salesTeamMember.get('OpportunityId')).add((Id)salesTeamMember.get('UserId'));
}
}
}
I see that you are instatiating a new Set in every iteration of the loop. This simply nulls out the previous one and creates a new object.
Regards,
Satish Kumar
Another samll query . I have used listOpportunityTeamMember list in the above code. Do I need to clear the list at the end of the method.
Does it affect the heap size or memory allocation.
Regards
But make sure you really do not need this data anymore in the list.
Regards,
Satish Kumar
Could you please have a look into the below code. Is is necessary to return null. Can we remove the picece of line.
@TestVisible private set<integer> monthsToAdd(date startingDate ,date endingDate ) {
if(startingDate != null && endingDate != null) {
for(monthIndex=startingDate.month() ; monthIndex<= endingDate.month() ; monthIndex++){
monthsSet.add(monthIndex);
}
return monthsSet;
}else {
return null;
}
}
Regards,
Satish Kumar