8

What I am trying to do is to set a date in my date field and also update the object. I am using the class below to do so which works just fine in my sanbox but in production I am getting this error:

System.LimitException: Too many query rows: 50001

public with sharing class updateObject{
    public  List<NRProducts__c>  values;
    public PageReference updateObject() {
        values=[SELECT Refreshed_Date__c FROM NRProducts__c ];
        for (NRProducts__c s :values){
           s.Refreshed_Date__c =Date.today();
         } 
        update values;
        return null;                  
    }    
}

VF Page:

<apex:page showheader="false" controller="updateObject" sidebar="false">
<apex:form> 
<apex:commandButton action="{!updateObject}" value="Update"/>
</apex:form>
</apex:page>
8

You're running into this on production, because you have much more data there than in your sandbox. This is a limit which is a bit harder to test against and discover in advance. You'd do well to integrate it into your salesforce developer conscious.

total number of records retrieved by SOQL queries = 50,000

You will need to use Batch Apex, in which the 50k limit counts per batch execution

These limits count for each Apex transaction. For Batch Apex, these limits are reset for each execution of a batch of records in the execute method.

This is clearly stated in the limit documentation. Salesforce enforces these rules to "force" us to use scaleable and resource friendly implementation patterns.

  • Samuel, Thank you for your answer. I am not familiar with Batch apex, could you please help me with this. Thank you in advance! – Carlos Feb 18 '14 at 21:39
  • I've added a documentation starting point. It's invoking an asynchronous process in which batches of data are processed through your execution method separately. (i assume to minimize the memory heap required for the execution) – Samuel De Rycke Feb 18 '14 at 21:40
  • Samuel, do you think that the example applies in my case, if so how do I link my button in the VF page with it? Thank you in advance!!!"The following class uses batch Apex to reassign all accounts owned by a specific user to a different user.: link – Carlos Feb 18 '14 at 22:17
  • well, that's an example. the point is that you'll need to shift your solution design to a different approach. You should be able to schedule or kick of a batch process from an apex controller. (do know that only a certain amount of parallel batches can be ran). – Samuel De Rycke Feb 18 '14 at 22:22
  • 1
    I am so new in apex, and I found so much support in this site from awesome people like you...I hope someday I will be helping others. Thanks again! – Carlos Feb 18 '14 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.