function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
andremsalgadoandremsalgado 

Too Many SOQL Queries - Don't know how to solve.

Gentlemen,

 

I am facing the problem with the following query:

 

Select  Id,

              Lookupfield_Table01__c,

              Lookupfiled_Table02__c  

 

             FROM  CustomObject01__c

             WHERE

                      Lookupfield_Table01__c IN (Select Id FROM CustomObject02__c Where CustomFiled01__c = true) AND

                      Lookupfiled_Table02__c IN (Select Id FROM Account Where CustomFiled02__c = false)

 

On error occurs, telling my there are too many SOQL steatmans.

 

Does anybody know some other way to write this query?

 

Thank you in advance,


André Salgado

 

 

 

 

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 
souvik9086souvik9086

Hi,

 

You might be using the soql query within loop. If yes then try to execute outside loop and see what happens, if no then try to use Batch Apex by setting the no of records executed less than 100 so that the error "Too Many SOQL: Queries" will not come.

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

All Answers

souvik9086souvik9086

Hi,

 

You might be using the soql query within loop. If yes then try to execute outside loop and see what happens, if no then try to use Batch Apex by setting the no of records executed less than 100 so that the error "Too Many SOQL: Queries" will not come.

 

If this post solves your problem kindly mark it as solution. if this post is helpful please throw Kudos.

Thanks

This was selected as the best answer
andremsalgadoandremsalgado
Thank you very much Souvik... The problem really was not in the Query...
souvik9086souvik9086

You are most welcome :). Yes the query is correct. Just we need to avoid writing those within loops to overcome this errors.