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
tangotango 

apex update more then 10k records?

I have an apex class that is set up mass update contact records. It spools through and updates some custom indexes that we use.

Currently it uses a a for loop to spool through and update contact 1k at a time. I am getting a governor warning :

Number of query rows: 9300 out of 10000
Number of DML rows: 9291 out of 10000

Is there a work around to updating more then 10k records via a class? I have it attached to a campaign button to update contacts from a current campaign and it is likely that we will have more then 10k.

mtbclimbermtbclimber
The limit is per-request so to accomplish your goal you will need to spread your processing across requests.
tangotango
thanks for the reply...

I am already using a List<> and updating 1k at a time. what is considered a 'request'?

Do I need to exit the class or can I just use a 10k counter and create another List object to update the next group over 10k?

Thanks



arnt72arnt72
not sure if this helps but have you read about the SOQL for Loops:
http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_loops_for_SOQL.htm
tangotango
I am already using List to bulk update the records and loops to iterate through the matching query set.

The problem is I am hitting governor limits for the action of 10k returned query rows.

How does the excel connector update 20k plus records via the api? I was just trying to create a button to save me from having to use an external tool like the excel connector.

here is the code I am using. it works right up until the returning query set is more then 10k... I tried using 3 different query loops but the governor limit seems to be cumulative for the entire class request because I get the same errors.



Code:
public class ContactCampaignIndex{ 

public void IndexApproved(){

List<Contact> CampIndex = new List<Contact>();
integer cindex = 0;
for(Contact Clist : [select ID,Campaign_Index__c, Opt_In__c from Contact where Opt_In__c = TRUE AND HasOptedOutOfEmail = FALSE])
    {
        Clist.Campaign_Index__c = cindex++; 
        if(CampIndex.size() == 1000) {
           try {
              update CampIndex ;
                  }catch (DmlException e) {
                      System.debug('Exception Updating Campaign index');
                     }
            CampIndex.clear();
          }else
          CampIndex.add(Clist);    
    } 
    if (CampIndex != null) 
    try {
          update CampIndex ;
          }catch (DmlException e) {
          System.debug('Exception Updating Campaign index');
           }
       else System.debug('no matching records');
     
}

 



SuperfellSuperfell
You'll need to have your button make multiple calls into your class, the HTTP request is the boundary for governor limits. However, I can't really see the point of you code, you don't even query contacts in a given order, so its basically going to be assigning a sequential number in a random order. Can't you just update the records that don't have an index set already, instead of re-updating all of them.