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

Issue regarding governor limits
Hello,
I am facing an error while running the Apex code as:
System.Exception: Too many SOQL queries: 10001
Can anyone provide me with a solution for this.
I went through the docs and the discussions for the governor limits but got confused by the posts .
Could any one provide a solution to this :
Your help will be appreciated ....
Thanks
shaan
You can use standard set controller as your query is fatching large number of records.
it will give u the pagination functionality on the records and may be helpful for you.
Thanks for ur help and quick reply....
Here i am able to retrieve the records upto a limit of 10000 records but after that i am getting the error.
Here is the code :
List<campaignmember> campaignList=new List<campaignmember>();
String campaignId=campaign.Id;
Set<Id> leadid = new Set<Id>();
Set<Id> contactid = new Set<Id>();
List<String> emails=new List<String>();
List<Integer> segmentList = new List<Integer>();
for (CampaignMember camp : [SELECT leadId, contactId FROM CampaignMember WHERE campaignId =: campaignId])
{
// Add the campaignMember's lead Id to the Set.
leadId.add(camp.leadId);
// If we have filled the set, process it and empty it.
if (leadId.size() > 999)
{
for (Lead lead: [Select Email from lead WHERE Id IN :leadId])
{
if(lead.Email != null)
{
emails.add(lead.Email);
}
leadId.clear();
}
if(emails.size()>0)
{
inputParam.segmentId = common.createImmediateSegment(userName,password,version,emails);
segmentList.add(inputParam.segmentId);
}
if(inputParam.segmentId==null)
{
//no segment id, so skip the process
return false;
}
}
// Now repeat for the Contact Id...
contactId.add(camp.contactId);
if (contactId.size() > 999)
{
for (Contact cnt: [Select Email from contact WHERE Id IN :contactid])
{
if(cnt.Email != null)
{
emails.add(cnt.Email);
}
contactId.clear();
}
if(emails.size()>0)
{
inputParam.segmentId = common.createImmediateSegment(userName,password,version,emails);
segmentList.add(inputParam.segmentId);
}
if(inputParam.segmentId==null)
{
//no segment id, so skip the process
return false;
}
}
emails.clear();
}
if(contactid.size() >0)
{
for (Contact cnt: [Select Email from contact WHERE Id IN :contactid])
{
if(cnt.Email != null)
{
emails.add(cnt.Email);
}
contactId.clear();
}
if(emails.size()>0)
{
inputParam.segmentId = common.createImmediateSegment(userName,password,version,emails);
segmentList.add(inputParam.segmentId);
}
if(inputParam.segmentId==null)
{
//no segment id, so skip the process
return false;
}
emails.clear();
}
if(leadId.size() >0)
{
for (Lead lead: [Select Email from lead WHERE Id IN :leadId])
{
if(lead.Email != null)
{
emails.add(lead.Email);
}
leadId.clear();
}
if(emails.size()>0)
{
inputParam.segmentId = common.createImmediateSegment(userName,password,version,emails);
segmentList.add(inputParam.segmentId);
}
if(inputParam.segmentId==null)
{
//no segment id, so skip the process
return false;
}
emails.clear();
}
the above code is working for the records upto 10000 limit.
please review the code and let me know if any changes to be made.
Thanks
shaan
Above i have posted my code please let me know if any changes??
in the code i was able to execute the queries upto 10000 but above that i am facing the error.
Thanks for u reply. I went through the docs for batch jobs got some information about creating the batch and implementing it.
can u provide me with an example for this.....
Your help is always appreciated