|
1 | 1 | ## Apex Chainable |
2 | | -TBD |
| 2 | +This library provides all the classes required to chain all kind of Async jobs. |
| 3 | + |
| 4 | +## Installation |
| 5 | +<a href="https://githubsfdeploy.herokuapp.com?owner=scolladon&repo=apex-chainable"> |
| 6 | + <img alt="Deploy to Salesforce" |
| 7 | + src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png"> |
| 8 | +</a> |
| 9 | + |
3 | 10 |
|
4 | 11 | ## Usage |
5 | | -TBD |
| 12 | +Create a class and extend the type of the chainable class you require. |
| 13 | +Your class can have its own constructors and its own attributes of course ! |
| 14 | +Respect the interface contract and override the job method. |
| 15 | +You need to override the start method also for the chain_Batch and chain_ScheduleBatch class |
| 16 | +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). |
| 17 | +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). |
| 18 | +You're ready to chain ! |
| 19 | +You do not need to override another method except if you really know what you're doing |
6 | 20 |
|
7 | 21 | ```apex |
8 | | -/*TODO*/ |
| 22 | +// Subclass Batch for example |
| 23 | +public class chain_Batch_EXAMPLE extends chain_Batch { |
| 24 | + public override Database.QueryLocator start(Database.BatchableContext bc) { |
| 25 | + return Database.getQueryLocator('select id from account limit 1'); |
| 26 | + } |
| 27 | +
|
| 28 | + public chain_Batch_EXAMPLE(){ |
| 29 | + super(); |
| 30 | + } |
| 31 | +
|
| 32 | + protected override void job() { |
| 33 | + System.Debug('chain_Batch_EXAMPLE'); |
| 34 | + } |
| 35 | +} |
| 36 | +
|
| 37 | +//Subclass Queue for example |
| 38 | +public class chain_Queue_EXAMPLE extends chain_Queue { |
| 39 | +
|
| 40 | + public chain_Queue_EXAMPLE(){ |
| 41 | + super(); |
| 42 | + } |
| 43 | +
|
| 44 | + protected override void job() { |
| 45 | + System.Debug('chain_Batch_EXAMPLE'); |
| 46 | + } |
| 47 | +} |
| 48 | +
|
| 49 | +// Chain both and execute them |
| 50 | +public class Service { |
| 51 | + public static void doService() { |
| 52 | + chain_Chainable aChain = new chain_Batch_EXAMPLE(); |
| 53 | + aChain.Add(new chain_Queue_EXAMPLE()); |
| 54 | +
|
| 55 | + aChain.executeChain(); |
| 56 | + } |
| 57 | +} |
9 | 58 | ``` |
10 | 59 |
|
11 | 60 | ## Improvement |
12 | 61 |
|
13 | | -BatchIterable and ScheduleBatchIterable |
| 62 | +Implement sub class allowing to handle Batch and ScheduleBatch with iterable in addition of QueryLocator |
| 63 | +Allow to benefit from [this pilot](https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_enhanced_future_overview.htm) for the chain_Future class |
14 | 64 |
|
15 | | -## Installation |
16 | | -<a href="https://githubsfdeploy.herokuapp.com?owner=scolladon&repo=apex-chainable"> |
17 | | - <img alt="Deploy to Salesforce" |
18 | | - src="https://raw.githubusercontent.com/afawcett/githubsfdeploy/master/deploy.png"> |
19 | | -</a> |
| 65 | +## Versioning |
| 66 | + |
| 67 | +[SemVer](http://semver.org/) is used for versioning. |
| 68 | + |
| 69 | +## Authors |
| 70 | + |
| 71 | +* **Sebastien Colladon** - *Initial work* - [scolladon](https://github.com/scolladon) |
| 72 | + |
| 73 | +## License |
| 74 | + |
| 75 | +This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details |
0 commit comments