New answers tagged

2

The batches are generated at the beginning (during the start method). As such, each subsequent batch would query any records that haven't yet updated. The solution is to re-query the accounts in the execute method to see if they still require the additional logic to be executed: public void execute(Database.BatchableContext context, Account[] scope) { ...


1

You missed a semi-colon at the end of line 3. List<Purchase_Order__Share> sharesToDelete = [SELECT Id FROM MyCustomObject__Share WHERE RowCause = 'Manual']; You also missed the second parameter's data type from the execute method, and misspelled execute. global void execute(Database.BatchableContext bc, Purchase_Order__Share[] sharesToDelete){ ...


2

You can use sObject update collections to deal with up to 200 records at once. It uses: PATCH /vXX.X/composite/sobjects This is the same basic feature as the SOAP equivalent. If you want to deal with many thousands of records with just a few API calls, the Bulk API may be right for you (see other answer). However, for most use cases, this API is perfectly ...


3

You can explore Bulk API. It has capabilities to load/process large chunks. You can see the limitations here - Bulk API Allocation Limits For more details on how to use, you can see Trailhead link - Trailhead Module


0

You're accessing the first Messaging.SendEmailResult in the list, but that may not be the one that has the error, so errors[0] throws this exception. Use the current iteration instead: //System.debug('The email failed to send: ' + results[0].errors[0].message); System.debug('The email failed to send: ' + r.errors[0].message);


2

Cron Expression Cron Expression syntax :- “Seconds Minutes Hours Day_of_month Month Day_of_week optional_year” 0 30 0 ? * * * at 12:30 AM every day


2

The System.schedule method uses your user time zone. So, ideally, you should set your time zone to CST first, or you'll have to calculate the difference. Once you do that, you run the method as: System.schedule(jobName, '0 30 0 ? ? *', scheduleInstance); Where: 0 Seconds 30 Minutes 0 Hours (12 AM in 24 hour form) ? Every Day ? Every Month * Any day of ...


0

Your main problem is that you should be returning the job Id to make sure you have the correct batch (more than one batch could be running). Second, imperative apex records return a different structure than that required for getFieldValue. Simply access the fields directly, or use a wired getRecord method.


0

There's no simple way to do this, as you'd run in to governor limits as soon as you had more than 2,000 accounts that meet this criteria. Your best choice, then, would be to query for all accounts with contacts, then determine which ones match at runtime. Here's a very basic version to get you started: public class Example1 implements Database.Batchable<...


0

Does the batch job rolls back the DML operations of a chunk if an error is encountered? Yes. If an unhandled exception occurs, all work done in the execute method will be rolled back. This is the same behavior you'd see in a trigger, future method, queueable, etc. Never allow an exception to be thrown to the top unless you want to abort the transaction ...


0

To resolve my issue, I had to navigate to the class that was calling the Database.executeBatch(new myBatchClass()); and remove with sharing on the class


0

Here is the second class being called in the Finish() method of the first: global class TerritoryAssignmentContacts implements Database.Batchable<sObject> { global Database.QueryLocator start(Database.BatchableContext ctx) { String query = 'SELECT ID FROM Contact WHERE OwnerId = //not sure how to get ID from variable here//'; return Database....


0

Database.QueryLocator getQueryLocator(List<SObject> query) only works with an inline query. The following would compile: public class SuperBatch implements Database.Batchable<SObject>, Database.Stateful { public Database.QueryLocator start(Database.BatchableContext param1) { return Database.getQueryLocator([SELECT Id FROM Account]); ...


0

In order to prevent a crash from killing your transaction entirely, I would suggest a Batchable class (or you could Queueable with Finalizer, but that may be overkill). The transformation is actually pretty easy: public class TerritoryAssignmentClass implements Database.Batchable<sObject> { @InvocableMethod(label = 'Update Records') public ...


0

It is strange, but only one possible way to schedule job in my case was setup the last (optional) argument. So to run job I have used: '0 0 6 ? * MON *' instead of:'0 0 6 ? * MON'. First when I tried to use '0 0 6 ? * MON' I constantly got error: System.StringException: Unexpected end of expression. The same issue was in tests. It is more strange, that after ...


Top 50 recent answers are included