Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/rsoesemann/apex-chainable
Chain Asynchronous Apex in a readable and flexible way without hardcoding the successor.
https://github.com/rsoesemann/apex-chainable
apex-batches asynchronous-programming batch batch-chains clean-code fluent-api framework queueable salesforce-apex schedulable successor-batch
Last synced: 2 months ago
JSON representation
Chain Asynchronous Apex in a readable and flexible way without hardcoding the successor.
- Host: GitHub
- URL: https://github.com/rsoesemann/apex-chainable
- Owner: rsoesemann
- License: mit
- Created: 2019-01-22T08:45:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-01-03T09:24:39.000Z (over 1 year ago)
- Last Synced: 2024-04-24T05:08:59.472Z (2 months ago)
- Topics: apex-batches, asynchronous-programming, batch, batch-chains, clean-code, fluent-api, framework, queueable, salesforce-apex, schedulable, successor-batch
- Language: Apex
- Homepage:
- Size: 27.3 KB
- Stars: 42
- Watchers: 6
- Forks: 9
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Lists
- awesome-salesforce - Apex Chainable Batch - Apex Batches can be chained by calling the successor batch from the `finish()` method of the previous batch. But such hardcoding makes this model inflexible. It's hard to build the chain from outside, neighter from a central class nor on runtime dependant on business logic. (Table of Contents / Packages and Libraries supporting salesforce)
README
# Apex Chainable [![Codacy Badge](https://app.codacy.com/project/badge/Grade/7024ec2e01c24c03a323e565e029a5a6)](https://www.codacy.com/gh/rsoesemann/apex-chainable/dashboard?utm_source=github.com&utm_medium=referral&utm_content=rsoesemann/apex-chainable&utm_campaign=Badge_Grade)
Apex Batches can be chained by calling the successor batch from the `finish()` method of the previous batch.
But such hardcoding makes this model inflexible. It's hard to build the chain from outside, neighter from a central class
nor on runtime dependant on business logic.The same applies when the `execute()` method of `Schedulable` or `Queueable` classes call other classes.
## With `Chainable`
The `Chainable` wrapper class of this repository overcomes those drawbacks.
- No need to hardcode successor batch in `finish()` method
- Created batch chains of arbitrary length without changing existing Batch classes
- Support `Batchable`, `Queueable` and `Schedulable` classes as chain members
- Allows sharing and passing of variables between chain members```java
new FirstBatch().setShared('result', new Money(0))
.then(AnotherBatch())
.then(QueueableJob())
.then(ScheduledJob())
...
.execute();
```## Without `Chainable`
```java
class FirstBatch implements Batchable {
Iterator start(BatchableContext ctx) { ... }void execute(BatchableContext ctx, List scope) { ... }
void finish(BatchableContext ctx) {
Database.enqueueBatch(new SecondBatch());
}
}
``````java
class AnotherBatch implements Batchable {
Iterator start(BatchableContext ctx) { ... }void execute(BatchableContext ctx, List scope) { ... }
void finish(BatchableContext ctx) {
System.schedule('name', cron, new ScheduledJob());
}
}
```