|
1 | | -## Apex AsyncLinkable |
| 1 | +## Apex AsyncLinkable  [](https://codecov.io/gh/scolladon/apex-async-linkable) |
2 | 2 |
|
3 | 3 | This library provides all the classes required to chain all kind of Async jobs. |
4 | 4 |
|
5 | 5 | ## Installation |
6 | 6 |
|
7 | 7 | ```bash |
8 | | -$ sfdx force:source:deploy -p path/to/source |
| 8 | +$ sfdx force:source:deploy -p chain/src/lib |
9 | 9 | ``` |
10 | 10 |
|
11 | 11 | ## Usage |
12 | 12 |
|
13 | | -Create a class and extend the type of the AsyncLinkable class you require.\ |
14 | | -Your class can have its own constructors and its own attributes of course !\ |
15 | | -Respect the interface contract and override the job method.\ |
16 | | -You need to override the start method also for the BatchLink and ScheduleBatchLink class\ |
17 | | -The job method will contains your business logic. It can access the private attributes of your class (and the protected ones of the base class).\ |
18 | | -If you need some extra interface to make you're code work, it is up to you to add them (Database.Stateful, Database.AllowsCallouts, etc).\ |
19 | | -You're ready to chain !\ |
20 | | -You do not need to override another method except if you really know what you're doing\ |
| 13 | +1. Create a class and extend the type of the `[AsyncLinkable](https://github.com/scolladon/apex-async-linkable/blob/master/chain/src/lib/classes/AsyncLinkable.cls)` class you require. |
| 14 | + _Your class can have its own constructors and its own attributes of course !_ |
| 15 | +2. Respect the interface contract and override the `job` method. |
| 16 | + _`start` method must also be overridden for the BatchLink and ScheduleBatchLink class_ |
| 17 | + |
| 18 | +The `job` method will contains your business logic. It can access the private attributes of your class (and the protected ones of the base class). |
| 19 | + |
| 20 | +If you need some extra interface to make you're code work, it is up to you to add them (`Database.Stateful`, `Database.AllowsCallouts`, etc). |
| 21 | + |
| 22 | +You're ready to chain apex asynchronous process! |
| 23 | + |
| 24 | +Example for Batchable: |
21 | 25 |
|
22 | 26 | ```apex |
23 | 27 | // Subclass BatchLink for example |
24 | 28 | public class BatchLink_EXAMPLE extends BatchLink { |
25 | | - public override Database.QueryLocator start(Database.BatchLinkableContext bc) { |
| 29 | + public override Database.QueryLocator start( |
| 30 | + Database.BatchLinkableContext bc |
| 31 | + ) { |
26 | 32 | return Database.getQueryLocator('select id from account limit 1'); |
27 | 33 | } |
28 | 34 |
|
29 | | - public BatchLink_EXAMPLE(){ |
| 35 | + public BatchLink_EXAMPLE() { |
30 | 36 | super(); |
31 | 37 | } |
32 | 38 |
|
33 | 39 | protected override void job() { |
34 | 40 | System.Debug('BatchLink_EXAMPLE'); |
35 | 41 | } |
36 | 42 | } |
| 43 | +``` |
| 44 | + |
| 45 | +Example for Queue: |
37 | 46 |
|
| 47 | +```apex |
38 | 48 | //Subclass QueueLink for example |
39 | 49 | public class QueueLink_EXAMPLE extends QueueLink { |
40 | | -
|
41 | | - public QueueLink_EXAMPLE(){ |
| 50 | + public QueueLink_EXAMPLE() { |
42 | 51 | super(); |
43 | 52 | } |
44 | 53 |
|
45 | 54 | protected override void job() { |
46 | 55 | System.Debug('BatchLink_EXAMPLE'); |
47 | 56 | } |
48 | 57 | } |
| 58 | +``` |
49 | 59 |
|
| 60 | +Example chaining `BatchLink_EXAMPLE` and `QueueLink_EXAMPLE`; |
| 61 | + |
| 62 | +```apex |
50 | 63 | // Chain both and execute them |
51 | 64 | public class Service { |
52 | 65 | public static void doService() { |
53 | | - AsyncLinkable aChain = new BatchLink_EXAMPLE(); |
54 | | - aChain.Add(new QueueLink_EXAMPLE()); |
55 | | -
|
56 | | - aChain.startChain(); |
| 66 | + ChainManager.instance |
| 67 | + .add(new BatchLink_EXAMPLE()) |
| 68 | + .add(new QueueLink_EXAMPLE()) |
| 69 | + .startChain(); |
57 | 70 | } |
58 | 71 | } |
59 | 72 | ``` |
60 | 73 |
|
61 | 74 | ## Improvement |
62 | 75 |
|
63 | 76 | Implement sub class allowing to handle BatchLink and ScheduleBatchLink with iterable in addition of QueryLocator\ |
64 | | -Allow to benefit from [this pilot](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_enhanced_FutureLink_overview.htm) for the FutureLink class |
65 | 77 |
|
66 | 78 | ## Versioning |
67 | 79 |
|
|
0 commit comments