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
parkerAPTparkerAPT 

@future method still has 10,000 DML row limit?

I'm trying to write an Apex Controller that will modify all of the contacts that are part of a campaign.
I want to do this asynchronously so that the user does not need to click and wait for the processing to take place.

I've tried implementing this as @future method but am running into the limit of 10,000 rows when there are more than 5,000 campaign members.
I hit this limit because I have to query all of the CampaignMembers (5,000) and then query and update all of the contacts (5,000).

I thought that @future methods did not have these kinds of DML limitations because they were executing asynchronously.

If that is not the case, can anyone suggest another way to modify all of the Contacts that are part of a Campaign?

Thanks alot.  I've attached the code as an example.
 

public class CampaignController { public Campaign theCampaign { get; set; } public CampaignController(ApexPages.StandardController stdController) { this.theCampaign = (Campaign)stdController.getRecord(); } public PageReference publishCampaign() { CampaignMananger.FlagCampaignMembersWithTag(this.theCampaign.id); return null; }}global class CampaignMananger { @future public static void FlagCampaignMembersWithTag(ID campaignID){ for(List<CampaignMember> membersC : [Select c.Status, c.Id, c.ContactId, c.CampaignId From CampaignMember c WHERE c.CampaignId = :campaignID ]) { List<ID> theContactIds = new List<ID>(); for(CampaignMember cm : membersC){ theContactIds.add(cm.ContactId); } List<Contact> theContacts = [SELECT c.id, c.CustomTag__c FROM Contact c where c.id in :theContactIds ]; for(Contact c : theContacts ){ c.CustomTag__c = 'Marked as Sent a Campaign'; } update theContacts; } }}