Hot answers tagged

3

Your current code is not correct for batch execution. It simply retrieves and stars processing those records itself. Batch apex allows you to create a batchable apex class (need to use interface) with three methods, which allows Salesforce to: identify work, that is, no. of records to be divided into multiple batches (Start method) execute each batch (...


3

There is no restriction preventing EventBus.publish from a Database.Batchable. You can publish platform events without implementing Database.RaisePlatformEvents. The only effect of this interface is that it automatically publishes BatchApexErrorEvent records in the case of an unhanded exception.


2

First of all, you're missing a ' in your code (if this is a copy-paste error, feel free to ignore this advice). Syntax highlighting could have helped you here: Second, you did have an extra parentheses: 'WHERE ((Status = \'SS\' OR Status = \'WF\' AND RecordTypeAPI__c NOT IN:RecordTypeName)'+ // ^--There were three here Third, you don't need the string, ...


2

The error is here: if( string.contains(b.Background_Check_Done__c = 'No')). b.Background_Check_Done__c = 'No' is an assignment. A check would be b.Background_Check_Done__c == 'No'. contains() isn't a static method of String class, so you must call it on an instance. Its signature is public Boolean contains(String substring) so even if you write contains(b....


2

Database.Batchable<AggregateResult> requires an Iterable<AggregateResult>. If you change your code to Database.Batchable<sObject>, your code would compile just fine. Note that AggregateResult queries are limited to 2000 rows, so if you have more than that, you'll get an exception. As a side note, you can use an inline query instead of the &...


1

The QueryLocator that a Batchable class uses is subject to a 50,000,000 row limit, not just 50,000 that you get in most other contexts. Do keep in mind, though, you've only got 12,000,000 bytes of heap, so you will need to do your aggregation in each execute method; you can't store all the records in memory to the end. Also, as a performance enhancement, don'...


1

I can think of a couple of approaches 1 - Store the datetime in Custom Metadata. You can do this easily by exploiting this andyinthecloud GitHub repo . I have done this in one of my applications. You could also use a custom object. 2 - If possible, make the batch job idempotent so it can run with a filter like TODAY. If it encounters records it has already ...


Only top voted, non community-wiki answers of a minimum length are eligible