• nwyse.solutions1.3923304208688765E12
  • NEWBIE
  • 0 Points
  • Member since 2014

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
    Questions
  • 0
    Replies
Error that I am getting when a scheduled batch job tries to update the contacts running the below batch class code :

Error : Feedback API _ Scheduled Job _Too many query rows: 50001

global with sharing class ContactBatch implements Database.Batchable, Schedulable, Database.AllowsCallouts { global static final Integer BATCH_SIZE = 10; public static final String RECR = 'RECR'; global List failedContacts = new List(); global List contactsToUpdate = new List(); global List admissionsOppsToUpdate = new List();

global void execute(SchedulableContext SC) {
    ContactBatch contactBatch = new ContactBatch();
    Database.executeBatch(contactBatch, BATCH_SIZE);
}

global List<Contact> start(Database.BatchableContext BC) {
    String recrValue = RECR;
    String contactId = '003V000000FZfaZ';
    String query = 'SELECT {0}, (SELECT {1} FROM Applications__r WHERE isDeleted = false ORDER BY CreatedDate DESC)' +
        ' FROM Contact WHERE FieldsHaveChanged__c = true AND isDeleted = false';// AND Id = :contactId';
System.debug(query); Set uniqueContactFields = new Set(SparkroomServices.contactFieldsToCheckFromLmsCustomSetting); uniqueContactFields.add('Current_Opp_Id__c'); uniqueContactFields.add('Inactivation_Reason__c'); uniqueContactFields.add('Service_Indicators_Non_Editable__c'); uniqueContactFields.add('Service_Indicators_Editable__c'); uniqueContactFields.add('Recruiting_Status__c'); uniqueContactFields.add('Residency_Status__c'); String contactFields = String.join(new List(uniqueContactFields), ', '); Set uniqueAdmissionOppFields = new Set(SparkroomServices.admissionOppFieldsToCheckFromLmsCustomSetting); uniqueAdmissionOppFields.add('Start_Term__c'); uniqueAdmissionOppFields.add('Sparkroom_Lead_ID__c'); String admissionOppFields = String.join(new List(uniqueAdmissionOppFields), ', '); query = String.format(query, new List{contactFields, admissionOppFields}); return Database.query(query); }

global void execute(Database.BatchableContext BC, List<Contact> contacts) {
    SparkroomServices.runBatch(contacts, failedContacts, contactsToUpdate, admissionsOppsToUpdate);
}

global void finish(Database.BatchableContext BC) {

}
}

The query is ContactBatch contactBatch = new ContactBatch(); Database.executeBatch(contactBatch, 5);

Please help.

Thanks,

Nik