You need to sign in to do that
Don't have an account?
Violet
How to create a batch class to just update the Contacts defined in a trigger?
I have a trigger on Account that updates all child Contact objects but I am hitting a DML error due to number of Contacts on the Account. I want to call a batch class from the trigger if the list of Contacts is larger than 10000 (DML limit).
Is there a way to define the batch class in a way that it just takes the list of Contacts and updates them in batch? This is what I have for the batch and it is giving bunch of errors
This is how I am calling from the trigger
Is there a way to define the batch class in a way that it just takes the list of Contacts and updates them in batch? This is what I have for the batch and it is giving bunch of errors
global class SG_BatchContactUpdate implements Database.Batchable<sObject>{ Map<Id, Contact> contactmap = new Map<Id, Contact>(); global SG_BatchContactUpdate (Map<Id, Contact> contacts) { contactmap=contacts; } global Database.QueryLocator start(Database.BatchableContext BC) { return DataBase.getQueryLocator([SELECT Id FROM Contact WHERE Id IN : contactmap.keySet()]); } //Execute Method. global void execute(Database.BatchableContext BC) { } }
This is how I am calling from the trigger
Database.executeBatch(new SG_BatchContactUpdate(contactsToUpdate));
All Answers