+ Start a Discussion
asdf@asdf.ax408asdf@asdf.ax408 

APEX GOVERNOR LIMITS

Hi ,
         I am facing some issues on apex governor  limits. can anyone please tel me how to use getQueries() and getLimitQueries() in an simple Apex class..
tmatthiesentmatthiesen
example:
List<Account> accnts = [select id from account limit 1000];
system.debug('I have performed '+Limits.getQueries()+' and I am allowed up to '+Limits.getLimitQueries()+ ' within this request');

Take a look at the docs for further details: http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#StartTopic=Content/apex_methods_system_limits.htm
TehNrdTehNrd
Fyi you can also put the limits method directly into your query:

Code:
List<Account> accnts = [select id from account limit :Limits.getLimitQueries()];

//Then you could check to see if the max was reached:
if(Limits.getQueries() == Limits.getLimitQueries()){
 system.debug('The max number of records were returned and the List may be incomplete.');
}

 



Edward GeeEdward Gee
In your example, I believe you meant to use Limits.getQueryRows and Limits.getLimitQueryRows.  Plus, you also need to take into account how many other rows were retrieved before this line of code has been executed or else you'll see an exception thrown.

Code:
Integer limitRows = Limits.getLimitQueryRows() - Limits.getQueryRows();
List<Account> accnts = [select id from account limit :limitRows];
...
...