+ Start a Discussion
itsDoneitsDone 

How to calculate /fetch total number of opportunities in an org without hitting 50000 row limt

How to calculate /fetch total number of opportunities in an org without hitting 50000 row limt for SOQL ?

 

Thanks in advance!

kiranmutturukiranmutturu

try like this

 

Integer i = [select count() from opportunity];

itsDoneitsDone

I tried this, row limit still applies to count()

kiranmutturukiranmutturu

then its better to use for loop then

list<opportunity> lstid = new list<opportunity>();

 

for(opportunity opp : [select id from opportunity])

lstid.add(opp.id);

 

integer icount = lstid.size();

 

but sure there is a work around...but for the time being i got this solution                                

kiranmutturukiranmutturu

then its better to use for loop then

list<opportunity> lstid = new list<opportunity>();

 

for(opportunity opp : [select id from opportunity])

lstid.add(opp.id);

 

integer icount = lstid.size();

 

but sure there is a work around...but for the time being i am posting this                                

JPClark3JPClark3

As soon as Winter 12 is released you can create a small static method with the @ReadOnly annotation.

 

It allows an unlimited record count. All you need is [Select Count() FROM ***** ]; inside the method.