+ Start a Discussion
sivaextsivaext 

SOQL Query Limit

Hi , 

I have requirement to build custom reports for sales people performance for current financial years. We have going display data based user selection but each user's data crossing 60,000 + records. As per SOQL query limit for rows is 50000. 

Please help to handle this situation?

Thanks 
SIva.
pconpcon
How are you building this custom report?  Are you doing this in VisualForce or are you using the standard reporting interface?  If you are doing this in custom VisualForce the only real way around the SOQL query limit it to use the new @readOnly annotation [1].

[1] http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_classes_annotation_ReadOnly.htm
amber9904amber9904
If you're using the standard Salesforce reporting engine the following limits apply: https://help.salesforce.com/apex/HTViewHelpDoc?id=faq_reports_common_limits.htm&language=en_US
sivaextsivaext
Thanks pcon and amber. 

I am going to build using VF because standard report interface not meet client's requirement.
pconpcon
Then I think the @readOnly annotation is going to be your best bet.

If your issue is solved, please select a best answer to remove this question from the unanswered queue
William LópezWilliam López
Hello Sivaext, 

I see 2 options here, both of them using a batch.
http://www.salesforce.com/us/developer/docs/apexcode/Content/apex_batch_interface.htm

1) If each user need updated information:

For that you can create the VF page to ask the email of the user and have a button that will fire the run of a Batch. This page will say "You will get an email when your data its calculated"
 
In the batch you can split the data in smaller groups, 10k at the time for instance.

Once Batch completed, you can send an email in the finish method to the user, in that method you will sent the link of a second VF page, that second page will display totals. 

2) Partally Live data
If you want this live, you can ask that batch run to be executed every X hours, depending on clientes need can be once a day or once a week. And in the visual force page you show the informationa and a message "Data From XXXX date at XXX time".

In both cases you should use the "SystemModStamp"  or another date field to only porcess records that were not counted in the last summary.

I hope this helps.

Bill,

Regards.

Don't forget to mark your thread as 'SOLVED' with the answer that best helps you.