+ Start a Discussion
cooldamselcooldamsel 

[Urgent !!] Too Many SOQL queries : 101

Hi,

 

I have a recruitement application. I created a visualforce page where we need to select a month and it will display the report for the selected month.  My page worked well and there was no errors. I didn't give any queries in my loop. My test class also passed and moved the code to production environment. Everything was validated in the production and it was deployed successfully. But the issue is when i select certain month the page is displaying Too many SOQL queries.. But for certain other months selected there is no issue and the report is being generated.

 

Best Answer chosen by Admin (Salesforce Developers) 
Dhaval PanchalDhaval Panchal

Instead of below code

for(RequirementAssignment__c Reqmt : lstReqmtAssign)
{
	Requirement__c ReqmtsResume= [Select id, ResumesSubmitted__c, No_Of_Resumes__c from Requirement__c where id =: Reqmt.Requirement__c];
	lstReqmts.add(ReqmtsResume);
}

 

Use following code.

Set<ID> setReqId = new Set<ID>();
for(RequirementAssignment__c Reqmt : lstReqmtAssign)
{
	setReqId.add(Reqmt.Requirement__c);
}
if(setReqId.size()>0){
	List<Requirement__c> lstReqmtsResume= [Select id, ResumesSubmitted__c, No_Of_Resumes__c from Requirement__c where id in: setReqId];
	if(lstReqmtsResume.size()>0){
		for(Requirement__c req:lstReqmtsResume){
			lstReqmts.add(req);
		}
	}
}

 Also apply same thing for rest of code if any dml operation found in loop.

All Answers

Satish_SFDCSatish_SFDC

Hi,

Have you tried checking the debug logs.

Can you post the code snippet here, so we can check.

 

Regards,

Satish Kumar

cooldamselcooldamsel
Yeah in my development environment i checked the debug logs and it works fine in my dev environment. The issue is only in the production environment.
Dhaval PanchalDhaval Panchal
Might be your production evn contains more data then your dev env. So please copy your code. Might be some dml operation is in loop.
cooldamselcooldamsel

public with sharing class AssignRequirementReportClass
{
public String getMonths { get; set; }
public String getYear { get; set; }

public List<ReqmtAssignClass> LstReqmtAssignClass {get;set;}

public AssignRequirementReportClass()
{
}

Public Class ReqmtAssignClass
{
Public String strUser{get;set;}
Public String strDate1{get;set;}
Public String strDate2{get;set;}
Public String strDate3{get;set;}
Public String strDate4{get;set;}
Public String strDate5{get;set;}
Public String strDate6{get;set;}
Public String strDate7{get;set;}
Public String strDate8{get;set;}
Public String strDate9{get;set;}
Public String strDate10{get;set;}
Public String strDate11{get;set;}
Public String strDate12{get;set;}
Public String strDate13{get;set;}
Public String strDate14{get;set;}
Public String strDate15{get;set;}
Public String strDate16{get;set;}
Public String strDate17{get;set;}
Public String strDate18{get;set;}
Public String strDate19{get;set;}
Public String strDate20{get;set;}
Public String strDate21{get;set;}
Public String strDate22{get;set;}
Public String strDate23{get;set;}
Public String strDate24{get;set;}
Public String strDate25{get;set;}
Public String strDate26{get;set;}
Public String strDate27{get;set;}
Public String strDate28{get;set;}
Public String strDate29{get;set;}
Public String strDate30{get;set;}
Public String strDate31{get;set;}
Public String strTotal{get;set;}
}

public PageReference GetUserList()
{
List<User> lstUser = new List<User>([SELECT id, name from user where IsActive = true and userroleid in (select id from userrole where name='Lead Recruiter' or name = 'Recruiter')]);
System.Debug('User Lists : ' + lstUser);
List<RequirementAssignment__c> lstReqmtAssign = new List<RequirementAssignment__c>();
List<RequirementAssignment__c> FilterReqmtAssign ;
List<Requirement__c> lstReqmts = new List<Requirement__c>();
DateTime startDT=DateTime.newInstance(Integer.valueOf(getYear) , Integer.valueOf(getMonths) , 01,0,0,0);
System.Debug('Start Date:' + startDT);
DateTime endDT=DateTime.newInstance(Integer.valueOf(getYear) , Integer.valueOf(getMonths) , 31,23,59,59);
System.Debug('End DAte:' + endDT);
Date NewStartDate;
integer numberDaysDue = (startDT.dategmt()).daysBetween((endDT.dategmt()));
System.Debug('numberDaysDue :' + numberDaysDue);

if((numberDaysDue == 30) || (numberDaysDue == 31))
{
lstReqmtAssign = [select Status__c, Requirement__c, Lead_Recruiter__c, Recruiter__c, createddate from RequirementAssignment__c where (createddate >: startDT and createddate <: endDT) ];

System.Debug('Assign reqmt List:' +lstReqmtAssign);

for(RequirementAssignment__c Reqmt : lstReqmtAssign)
{
Requirement__c ReqmtsResume= [Select id, ResumesSubmitted__c, No_Of_Resumes__c from Requirement__c where id =: Reqmt.Requirement__c];
lstReqmts.add(ReqmtsResume);
}
System.Debug('Resumes reqmts:' +lstReqmts);

LstReqmtAssignClass = new List<ReqmtAssignClass>();
For(Integer row=0; row<2; row++)
{
LstReqmtAssignClass.add(GetRowData(startDT, endDT, row));
}
System.Debug('Assign Reqmts List:' + LstReqmtAssignClass);

for(User users: lstUser)
{
System.Debug('User Id:' + Users.id);
FilterReqmtAssign = new List<RequirementAssignment__c>();
for(RequirementAssignment__c ReqmAssign : lstReqmtAssign)
{
System.Debug('User Id:' + Users.id);
System.Debug('Assigned UserName:' +ReqmAssign.Lead_Recruiter__c);

if((Users.id == ReqmAssign.Lead_Recruiter__c) || (Users.id == ReqmAssign.Recruiter__c))
{
FilterReqmtAssign.Add(ReqmAssign);
}
System.Debug('Start Date:' + startDT);
System.Debug('Filetered USer:' +FilterReqmtAssign);
}

ReqmtAssignClass objReqmtAssignClass = new ReqmtAssignClass();
Integer count = 0;
NewStartDate = startDT.dategmt();

objReqmtAssignClass.strUser = users.name;

Integer UserReqmtCount = [select count() from RequirementAssignment__c where (Lead_Recruiter__c =: Users.id or Recruiter__c =: Users.id) and (createddate >: startDT and createddate <: endDT)];
System.Debug('User Reqmt Count:' +UserReqmtCount);
objReqmtAssignClass.strTotal = String.valueOf(UserReqmtCount);

if(FilterReqmtAssign != null)
{
for(RequirementAssignment__c ReqmAssignUser : FilterReqmtAssign)
{
System.Debug('Filtered Reqmt :' + ReqmAssignUser );
for(integer i=1; i<=31; i++)
{
DateTime ReqmtAssignDt = ReqmAssignUser.createddate;
Date ReqmAssignDate = Date.NewInstance(ReqmtAssignDt.yeargmt(), ReqmtAssignDt.monthgmt(), ReqmtAssignDt.daygmt());

System.Debug('Reqmt Assign Date:' +ReqmAssignDate);
System.Debug('Original Date:' + NewStartDate);
if(ReqmAssignDate == NewStartDate)
{
System.Debug('Before Count:' +count);
count ++;
System.Debug('Count:' +count);
}
else if(ReqmAssignDate < NewStartDate)
{
if(ReqmAssignUser.Status__c == 'Open')
{
for(Requirement__c ResumeReqmt : lstReqmts)
{
if(ReqmAssignUser.Requirement__c == ResumeReqmt.id)
{
if(ResumeReqmt.ResumesSubmitted__c != ResumeReqmt.No_Of_Resumes__c)
{
count++;
System.Debug('Incremented Count:' +count);
}
}
}
}
}

NewStartDate = (startDT.dategmt()).addDays(i);
System.Debug('Incremented Date:' + NewStartDate);
integer tot;
if(i==1)
{

if(objReqmtAssignClass.strDate1 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate1);
objReqmtAssignClass.strDate1 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate1 = String.valueOf(count);
system.Debug('objReqmtAssignClass.strDate1:' +objReqmtAssignClass.strDate1);
}
}
else if(i==2)
{
if(objReqmtAssignClass.strDate2 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate2 );
objReqmtAssignClass.strDate2 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate2 = String.valueOf(count);
count = 0;
}
}
else if(i==3)
{
if(objReqmtAssignClass.strDate3 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate3 );
objReqmtAssignClass.strDate3 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate3 = String.valueOf(count);
count = 0;
}
}
else if(i==4)
{
if(objReqmtAssignClass.strDate4 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate4 );
objReqmtAssignClass.strDate4 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate4 = String.valueOf(count);
count = 0;
}
}
else if(i==5)
{
if(objReqmtAssignClass.strDate5 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate5 );
objReqmtAssignClass.strDate5 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate5 = String.valueOf(count);
count = 0;
}
}
else if(i==6)
{
system.debug('Str Date6' +objReqmtAssignClass.strDate6);
if(objReqmtAssignClass.strDate6 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate6 );
objReqmtAssignClass.strDate6 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate6 = String.valueOf(count);
count = 0;
}
}
else if(i==7)
{
if(objReqmtAssignClass.strDate7 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate7 );
objReqmtAssignClass.strDate7 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate7 = String.valueOf(count);
count = 0;
}
}
else if(i==8)
{
if(objReqmtAssignClass.strDate8 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate8 );
objReqmtAssignClass.strDate8 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate8 = String.valueOf(count);
count = 0;
}
}
else if(i==9)
{
if(objReqmtAssignClass.strDate9 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate9 );
objReqmtAssignClass.strDate9 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate9 = String.valueOf(count);
count = 0;
}
}
else if(i==10)
{
if(objReqmtAssignClass.strDate10 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate10);
objReqmtAssignClass.strDate10 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate10 = String.valueOf(count);
count = 0;
}
}
else if(i==11)
{
if(objReqmtAssignClass.strDate11 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate11);
objReqmtAssignClass.strDate11 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate11 = String.valueOf(count);
count = 0;
}
}
else if(i==12)
{
if(objReqmtAssignClass.strDate12 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate12);
objReqmtAssignClass.strDate12 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate12 = String.valueOf(count);
count = 0;
}
}
else if(i==13)
{
if(objReqmtAssignClass.strDate13 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate13);
objReqmtAssignClass.strDate13 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate13 = String.valueOf(count);
count = 0;
}
}
else if(i==14)
{
if(objReqmtAssignClass.strDate14 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate14);
objReqmtAssignClass.strDate14 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate14 = String.valueOf(count);
count = 0;
}
}
else if(i==15)
{
if(objReqmtAssignClass.strDate15 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate15 );
objReqmtAssignClass.strDate15 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate15 = String.valueOf(count);
count = 0;
}
}
else if(i==16)
{
if(objReqmtAssignClass.strDate16 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate16);
objReqmtAssignClass.strDate16 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate16 = String.valueOf(count);
count = 0;
}
}
else if(i==17)
{
if(objReqmtAssignClass.strDate17 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate17);
objReqmtAssignClass.strDate17 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate17 = String.valueOf(count);
count = 0;
}
}
else if(i==18)
{
if(objReqmtAssignClass.strDate18 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate18 );
objReqmtAssignClass.strDate18 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate18 = String.valueOf(count);
count = 0;
}
}
else if(i==19)
{
if(objReqmtAssignClass.strDate19 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate19);
objReqmtAssignClass.strDate19 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate19 = String.valueOf(count);
count = 0;
}
}
else if(i==20)
{
if(objReqmtAssignClass.strDate20 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate20);
objReqmtAssignClass.strDate20 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate20 = String.valueOf(count);
count = 0;
}
}
else if(i==21)
{
if(objReqmtAssignClass.strDate21 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate21 );
objReqmtAssignClass.strDate21 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate21 = String.valueOf(count);
count = 0;
}
}
else if(i==22)
{
if(objReqmtAssignClass.strDate22 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate22);
objReqmtAssignClass.strDate22 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate22 = String.valueOf(count);
count = 0;
}
}
else if(i==23)
{
if(objReqmtAssignClass.strDate23 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate23);
objReqmtAssignClass.strDate23 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate23 = String.valueOf(count);
count = 0;
}
}
else if(i==24)
{
if(objReqmtAssignClass.strDate24 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate24);
objReqmtAssignClass.strDate24 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate24 = String.valueOf(count);
count = 0;
}
}
else if(i==25)
{
if(objReqmtAssignClass.strDate25 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate25);
objReqmtAssignClass.strDate25 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate25 = String.valueOf(count);
count = 0;
}
}
else if(i==26)
{
if(objReqmtAssignClass.strDate26 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate26 );
objReqmtAssignClass.strDate26 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate26 = String.valueOf(count);
count = 0;
}
}
else if(i==27)
{
if(objReqmtAssignClass.strDate27 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate27 );
objReqmtAssignClass.strDate27 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate27 = String.valueOf(count);
count = 0;
}
}
else if(i==28)
{
if(objReqmtAssignClass.strDate28 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate28);
objReqmtAssignClass.strDate28 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate28 = String.valueOf(count);
count = 0;
}
}
else if(i==29)
{
if(objReqmtAssignClass.strDate29 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate29);
objReqmtAssignClass.strDate29 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate29 = String.valueOf(count);
count = 0;
}
}
else if(i==30)
{
if(objReqmtAssignClass.strDate30 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate30 );
objReqmtAssignClass.strDate30 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate30 = String.valueOf(count);
count = 0;
}
}
else if(i==31)
{
if(objReqmtAssignClass.strDate31 != null)
{
tot = count + Integer.valueOf(objReqmtAssignClass.strDate31);
objReqmtAssignClass.strDate31 = String.valueOf(tot);
count = 0;
}
else
{
objReqmtAssignClass.strDate31 = String.valueOf(count);
count = 0;
}
}
}
}
}
LstReqmtAssignClass.add(objReqmtAssignClass);
System.Debug('List Reqmt Assign:' +LstReqmtAssignClass);
}
LstReqmtAssignClass.add(GetColumnTotal(startDT, endDT, lstReqmtAssign));
System.Debug('ListReqmtAssihnTotal:' +LstReqmtAssignClass);
}
return null;
}

}

cooldamselcooldamsel

public ReqmtAssignClass GetRowData(DateTime fromDT, DateTime toDT, Integer rowNumber)
{
ReqmtAssignClass objreqmtAssign = new ReqmtAssignClass(); 
Date fromDate = fromDT.dategmt();
Date toDate = toDT.dategmt();
integer daysDiff = fromDate.daysBetween(toDate);
System.Debug('DaysDiff:' +daysDiff);

if((daysDiff == 30) || (daysDiff == 31)) 
{
if(rowNumber == 0)
{
objreqmtAssign.strUser = 'Date' ;
for(integer dateRow=0; dateRow<31; dateRow++)

Integer inputDate; 
if(dateRow == 0)
{
inputDate = fromDate.day(); 
objreqmtAssign.strDate1 = String.valueOf(inputDate);
}
else if(dateRow == 1)
{
inputDate = (fromDate.addDays(dateRow)).day(); 
objreqmtAssign.strDate2 = String.valueOf(inputDate);
}
else if(dateRow == 2)
{
inputDate = (fromDate.addDays(dateRow)).day(); 
objreqmtAssign.strDate3 = String.valueOf(inputDate);
}
else if(dateRow == 3)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate4 = String.valueOf(inputDate);
}
else if(dateRow == 4)
{
inputDate = (fromDate.addDays(dateRow)).day(); 
objreqmtAssign.strDate5 = String.valueOf(inputDate);
}
else if(dateRow == 5)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate6 = String.valueOf(inputDate);
}
else if(dateRow == 6)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate7 = String.valueOf(inputDate);
}
else if(dateRow == 7)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate8 = String.valueOf(inputDate);
}
else if(dateRow == 8)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate9 = String.valueOf(inputDate);
}
else if(dateRow == 9)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate10 = String.valueOf(inputDate);
}
else if(dateRow == 10)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate11 = String.valueOf(inputDate);
}
else if(dateRow == 11)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate12 = String.valueOf(inputDate);
}
else if(dateRow == 12)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate13 = String.valueOf(inputDate);
}
else if(dateRow == 13)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate14 = String.valueOf(inputDate);
}
else if(dateRow == 14)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate15 = String.valueOf(inputDate);
}
else if(dateRow == 15)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate16 = String.valueOf(inputDate);
}
else if(dateRow == 16)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate17 = String.valueOf(inputDate);
}
else if(dateRow == 17)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate18 = String.valueOf(inputDate);
}
else if(dateRow == 18)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate19 = String.valueOf(inputDate);
}
else if(dateRow == 19)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate20 = String.valueOf(inputDate);
}
else if(dateRow == 20)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate21 = String.valueOf(inputDate);
}
else if(dateRow == 21)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate22 = String.valueOf(inputDate);
}
else if(dateRow == 22)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate23 = String.valueOf(inputDate);
}
else if(dateRow == 23)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate24 = String.valueOf(inputDate);
}
else if(dateRow == 24)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate25 = String.valueOf(inputDate);
}
else if(dateRow == 25)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate26 = String.valueOf(inputDate);
}
else if(dateRow == 26)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate27 = String.valueOf(inputDate);
}
else if(dateRow == 27)
{
inputDate = (fromDate.addDays(dateRow)).day(); 
objreqmtAssign.strDate28 = String.valueOf(inputDate);
}
else if(dateRow == 28)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate29 = String.valueOf(inputDate );
}
else if(dateRow == 29)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate30 = String.valueOf(inputDate );
}
else if(dateRow == 30)
{
inputDate = (fromDate.addDays(dateRow)).day();
objreqmtAssign.strDate31 = String.valueOf(inputDate );
}
}
}
else
{
String dayOfWeek;
objreqmtAssign.strUser = 'Day';
for(integer dayRow=0; dayRow<31; dayRow++)

Datetime fromDateTime = DateTime.newInstance(fromDate, Time.newInstance(0, 0, 0, 0));

if(dayRow == 0)
{
dayOfWeek = fromDateTime.format('EEE');
//System.Debug('Day value:' +dayOfWeek);
objreqmtAssign.strDate1 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 1)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate2 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 2)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate3 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 3)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate4 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 4)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate5 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 5)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate6 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 6)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate7 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 7)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate8 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 8)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate9 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 9)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate10 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 10)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate11 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 11)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate12 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 12)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate13 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 13)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate14 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 14)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate15 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 15)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate16 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 16)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate17 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 17)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate18 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 18)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate19 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 19)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate20 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 20)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate21 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 21)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate22 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 22)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate23 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 23)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate24 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 24)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate25 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 25)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate26 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 26)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate27 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 27)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate28 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 28)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate29 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 29)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate30 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
else if(dayRow == 30)
{
dayOfWeek = fromDateTime.format('EEE');
objreqmtAssign.strDate31 = dayOfWeek; 
fromDate = fromDate.addDays(1);
}
}
}
return objreqmtAssign; 

}


cooldamselcooldamsel

public ReqmtAssignClass GetColumnTotal(DateTime totalFromDt, DateTime totalToDt, List<RequirementAssignment__c> lstTotReqmtAssign)
{
ReqmtAssignClass objReqmentAssign = new ReqmtAssignClass(); 
Date totalFromDate = totalFromDt.dategmt();
Date totalToDate = totalToDt.dategmt();
Integer totalCount = 0;
Date NewTotalStartDate = totalFromDate; 
objReqmentAssign.strUser = 'Total'; 
for(integer totalRow =1; totalRow <=31; totalRow ++)
{
for(RequirementAssignment__c TotReqmAssign : lstTotReqmtAssign)

DateTime TotReqmtAssignDt = TotReqmAssign.createddate;
Date TotReqmAssignDate = Date.NewInstance(TotReqmtAssignDt.yeargmt(), TotReqmtAssignDt.monthgmt(), TotReqmtAssignDt.daygmt()); 
System.Debug('Tot Reqmt Assign Date:' +TotReqmAssignDate);
System.Debug('Tot Original Date:' + NewTotalStartDate); 
if(TotReqmAssignDate == NewTotalStartDate)

System.Debug('Before Tot Count:' +totalCount); 
totalCount ++; 
}
}

NewTotalStartDate = (totalFromDate).addDays(totalRow);
System.Debug('Incremented Tot Date:' + NewTotalStartDate); 
if(totalRow == 1)
{
objReqmentAssign.strDate1 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 2)
{
objReqmentAssign.strDate2 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 3)
{
objReqmentAssign.strDate3 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 4)
{
objReqmentAssign.strDate4 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 5)
{
objReqmentAssign.strDate5 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 6)
{
objReqmentAssign.strDate6 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 7)
{
objReqmentAssign.strDate7 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 8)
{
objReqmentAssign.strDate8 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 9)
{
objReqmentAssign.strDate9 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 10)
{
objReqmentAssign.strDate10 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 11)
{
objReqmentAssign.strDate11 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 12)
{
objReqmentAssign.strDate12 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 13)
{
objReqmentAssign.strDate13 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 14)
{
objReqmentAssign.strDate14 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 15)
{
objReqmentAssign.strDate15 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 16)
{
objReqmentAssign.strDate16 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 17)
{
objReqmentAssign.strDate17 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 18)
{
objReqmentAssign.strDate18 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 19)
{
objReqmentAssign.strDate19 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 20)
{
objReqmentAssign.strDate20 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 21)
{
objReqmentAssign.strDate21 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 22)
{
objReqmentAssign.strDate22 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 23)
{
objReqmentAssign.strDate23 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 24)
{
objReqmentAssign.strDate24 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 25)
{
objReqmentAssign.strDate25 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 26)
{
objReqmentAssign.strDate26 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 27)
{
objReqmentAssign.strDate27 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 28)
{
objReqmentAssign.strDate28 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 29)
{
objReqmentAssign.strDate29 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 30)
{
objReqmentAssign.strDate30 = string.valueOf(totalCount);
totalCount = 0;
}
else if(totalRow == 31)
{
objReqmentAssign.strDate31 = string.valueOf(totalCount);
totalCount = 0;
}
}
return objReqmentAssign;
}

 

This is my entire code... I have written the two methods of the class seperately as am not able to post more than 20000 characters... Please help me out..

Dhaval PanchalDhaval Panchal

See following piece of code which is from your code

for(RequirementAssignment__c Reqmt : lstReqmtAssign)
{
	Requirement__c ReqmtsResume= [Select id, ResumesSubmitted__c, No_Of_Resumes__c from Requirement__c where id =: Reqmt.Requirement__c];
	lstReqmts.add(ReqmtsResume);
}

 You have used query in loop. Suppose lstReqmtAssign has more than 100 records then query will fired 100 times. So remove this query from loop and also check same for rest of code.

Dhaval PanchalDhaval Panchal

Instead of below code

for(RequirementAssignment__c Reqmt : lstReqmtAssign)
{
	Requirement__c ReqmtsResume= [Select id, ResumesSubmitted__c, No_Of_Resumes__c from Requirement__c where id =: Reqmt.Requirement__c];
	lstReqmts.add(ReqmtsResume);
}

 

Use following code.

Set<ID> setReqId = new Set<ID>();
for(RequirementAssignment__c Reqmt : lstReqmtAssign)
{
	setReqId.add(Reqmt.Requirement__c);
}
if(setReqId.size()>0){
	List<Requirement__c> lstReqmtsResume= [Select id, ResumesSubmitted__c, No_Of_Resumes__c from Requirement__c where id in: setReqId];
	if(lstReqmtsResume.size()>0){
		for(Requirement__c req:lstReqmtsResume){
			lstReqmts.add(req);
		}
	}
}

 Also apply same thing for rest of code if any dml operation found in loop.

This was selected as the best answer
cooldamselcooldamsel
Thank you. I will deploy my code in production.