Salesforce Batch Class to Mass Delete Records from an Object
Salesforce Batch Apex can be used to mass or bulk delete records from objects in batches which will avoid hitting DML Governor Limit. Check the following sample Batch Apex class to ....
Salesforce Batch Apex can be used to mass or bulk delete records from objects in batches which will avoid hitting DML Governor Limit. Check the following sample Batch Apex class to ....
Batch Apex classes can fire platform events when encountering an error or exception. Event records provide more granular tracking of errors than the Apex Jobs UI because they include the ....
1. You can add up to 50 jobs to the queue with System.enqueueJob in a single transaction. 2. When chaining jobs with System.enqueueJob, you can add only one job from ....
Use System.abortJob( '<JobID>' ) to abort the apex job in Salesforce. To get the JobId, use the "AsyncApexJob" object. Add proper WHERE condition to the SOQL to find the Job Ids.SOQL:SELECT ....
AccountEffectiveBatch - Batch class to fetch Account records matching effectiveDate.AccountEffectiveBatchSchedule - Scheduler to call schedule it daily. This will call the AccountEffectiveBatch class and pass today's date.AccountEffectiveBatchSchedule is scheduled to ....
The call to Database.executeBatch should be included within the Test.startTest and Test.stopTest block. The job executes after the call to Test.stopTest. Any asynchronous code included within Test.startTest and Test.stopTest is ....
Sample Code: global class SampleBatch Implements Database.Batchable <sObject> { global Database.queryLocator start( Database.BatchableContext bc ) { String SOQL = 'SELECT Id, Name FROM Account LIMIT 1'; return Database.getQueryLocator(SOQL); } global void execute( Database.BatchableContext bc, List < sObject > scope ) { } global void finish( Database.BatchableContext bc ) { AsyncApexJob a = [ SELECT Id, Status, NumberOfErrors, JobItemsProcessed, TotalJobItems, CreatedById FROM AsyncApexJob WHERE Id =: bc.getJobId() ]; Messaging.SingleEmailMessage batchEmail = new Messaging.SingleEmailMessage(); batchEmail.setTargetObjectId( a.CreatedById ); batchEmail.setSubject( 'Batch ' + a.Status ); batchEmail.setPlainTextBody( 'Jobs processed ' + a.JobItemsProcessed + ' with '+ a.NumberOfErrors + ' failures.' ); batchEmail.setSaveAsActivity( false ); Messaging.sendEmail( new Messaging.SingleEmailMessage[] {batchEmail} ); } } ....
Constructor can be used for passing parameters to Batch Apex in Salesforce. Sample Batch Class: global class SampleBatchClassWithParams implements Database.Batchable<sObject>, Database.Stateful { private String strParam; private Set < Id > ....
Sample Code: SchedulerClass obj = new SchedulerClass(); String cron = '0 30,30,30 8,12,15 * * ? *'; System.schedule('SchedulerClass', cron, obj); In the above example, SchedulerClass will run daily at 8.30 ....
Sample Code: sObject__c sObj = [SELECT Id, FROM sObject__c WHERE your_condition]; Database.BatchableContext bc; BatchClass obj = new BatchClass(); obj.execute(bc, new List<sObject__c> {sObj}); Similarly you can test start and finish methods too. ....