I am getting this error though limit 100 is provided in SOQL statement.Can someone please suggest a way out here? Apex code:
public class Attachments_11{
public List<attachmentCaseWrapper> caseWrapper= new List<attachmentCaseWrapper>();
public void Attachments_11(){}
public List<Attachment> getattachedFiles() {
List<Attachment> attachedFiles = [select ParentId,ID,Parent.Name from Attachment limit 10];
return attachedFiles ;
}
public List<attachmentCaseWrapper> getcaseWrapper(){
LIST <ID> K=new List<Id>();
for(attachment a :[SELECT PARENTID FRom attachment where Parent.recordtype.sobjecttype='Account'])
{k.add(a.parentid);}
//List<Call2_vod__c> listCases = new List<Call2_vod__c>([select Account_vod__c,name,Account_vod__r.Name,id from Call2_vod__c where signature_date_vod__c!=Null and account_vod__C in :k limit 10 ]);
//List<Id> hcp=new List<Id>();
list<list<Call2_vod__c>> listOfLists = new list<list<Call2_vod__c>>();
list<Call2_vod__c> listOfContacts = new list<Call2_vod__c>();
for (Call2_vod__c c : [select Account_vod__c,name,Account_vod__r.Name,id from Call2_vod__c where signature_date_vod__c!=Null and account_vod__C in :k limit 100] )
{
if (listOfContacts.size() > 999)
{
listOfContacts = new list<Call2_vod__c>();
listOfLists.add(listOfContacts);
}
listOfContacts.add(c);
}
//and the last set...
listOfLists.add(listOfContacts);
system.debug(listOfLists.size());
for (list<Call2_vod__c> cons : listOfLists)
{
system.debug(cons.size());
for (Call2_vod__c con : cons)
{
system.debug(con.Name);
for (Attachment atf : [Select Id,Name,ParentId from attachment where parentId =:con.Account_vod__c AND Parent.recordtype.sobjecttype='Account' limit 1]) {
map<id,Attachment> mapCaseAttachments = new map<id,attachment>();
mapCaseAttachments.put(atf.ParentId,atf);
System.debug('keys in the map: ' + mapCaseAttachments.keySet());
System.debug('list of values in the map : ' + mapCaseAttachments.values());
}
}
}
/*for(Call2_vod__C c : listCases )
{
hcp.add(c.account_vod__C);
}*/
//for1
map<id,Attachment> mapCaseAttachments = new map<id,attachment>();
for (List<Call2_vod__c> cs : listOfLists) {
for (Call2_vod__c c : cs) {
attachment atf = mapCaseAttachments.get(c.Account_vod__C);
attachmentCaseWrapper cw = new attachmentCaseWrapper(c,atf);
caseWrapper.add(cw);
}
}
// for2
return caseWrapper;
}
public class attachmentCaseWrapper {
public string Call_Name {get; set;}
public string accountName {get; set;}
public string attachmentId {get; set;}
public attachmentCaseWrapper (Call2_vod__c cse, Attachment atf) {
Call_Name = cse.Name;
accountName = cse.Account_vod__r.Name;
if (atf != null) {
attachmentId = atf.id;
System.debug('***************************************************attachmentId : ' + atf.id);
}
}
}
}
Apex Page:
<apex:page controller="Attachments_11" renderas="pdf" >
<apex:form id="theForm">
<apex:pageBlock id="details">
<apex:pageBlockTable value="{!caseWrapper}" var="j">
<apex:column value="{!j.accountName}"/>
<apex:column >
<img src="/servlet/servlet.FileDownload?file={!j.attachmentId}"/>
<!--apex:image url="/servlet/servlet.FileDownload?file={!j.attachmentId}"/-->
</apex:column>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
Error: Too many SOQL Queries 101
for (list<Call2_vod__c> cons : listOfLists) {}
try to optimize your code as much as possible