You need to sign in to do that
Don't have an account?
Too many SOQL queries: 101 how can we avoid this exception
Hello,
I am using a soql query to retrieve records from contact.
Here is my query:
List<contact> contactList=[Select name,Email from contact where id=:contactId];
I am able to execute this if i have less records but if i have more records that is fr about 200 Records i am getting an exception:
Too many SOQL queries: 101 .
When i looked for this Exception i came to know that a database statement cannot process more than 100 records.
Is there any method to overcome this issue please help me out with code if any.
Please help me out of this issue.
Thanks in advance,
prashanth.
Hello VF,
Can you post your whole controller code? I'd be happy to help out.
Actually, the error you're receiving is indicating that your running too many queries, and not referring to the number of rows returned. Since the SoQL you show can only return 1 record at a time, I'm guessing you're calling it from inside of a loop so it gets executed multiple times. You'll need to take that query out of the loop and retrieve all of the Contact records you need to process at one time using a where clause with IN, i.e. "where id IN:contactIds" (where contactIds is a set of Ids). Depending on what you're trying to accomplish, you might want to put those Contacts into a Map so they can be retrieved by Id.
Hope that helps, but if not, post the full code.
Hey
You are using this query within a loop right? If this is the case you need to change your code. An example of a solution can be found here.
If you're having trouble adapting your code drop me a mail and I'll help you.
Cheers,
Wes
Thanks a lot guyz....the idea worked i had a Query inside the for loop.
I placed it outside the loop and made use of set ids .
Every thing working fine now .
Thanks once again....:smileyhappy:
I'm getting this error. If someone could help me bulkify this that would be AMAZING
public void entryexitUpload(){
nameFile=contentFile.toString();
filelines = nameFile.split('\n');
Map<Integer,Entry_Exit_Criteria_setup__c> eec=new Map<Integer,Entry_Exit_Criteria_setup__c>();
Entry_Exit_Criteria_setup__c neweec;
for (Integer n=1;n<filelines.size();n++){
String[] inputvalues = new String[]{};
inputvalues = filelines[n].split(',');
Entry_Exit_Criteria_setup__c entryexit= new Entry_Exit_Criteria_setup__c();
entryexit.Name=inputvalues[2];
entryexit.Criteria_Description__c=inputvalues[8];
entryexit.Enabled_Flag__c=Boolean.valueOf(inputvalues[9]);
entryexit.Criteria_Type__c=inputvalues[10];
try{
Level2__c level2Records=[SELECT Id,Name FROM Level2__c where Name=:inputvalues[12].trim() and Level2__c.Level1__r.name =:inputvalues[14].trim()];
entryexit.Level2__c=level2Records.Id;
}catch(Exception e){}
eec.put(n,entryexit);
neweec=eec.get(n);
insert neweec;
entryexitStatus=' '+(filelines.size()-1)+' Records Uploaded Successfully';
statusColor='green';
}
}