Skip to content

Commit c6b472f

Browse files
authored
Merge pull request #10 from beyond-the-cloud-dev/docs/updates
2 parents 2b518a2 + 68c04f9 commit c6b472f

File tree

8 files changed

+1009
-12
lines changed

8 files changed

+1009
-12
lines changed

website/api/batchable.md

Lines changed: 123 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,123 @@
1-
# Batchable
1+
# Batchable API
2+
3+
Apex classes `BatchableBuilder.cls` and `BatchableManager.cls`.
4+
5+
Common Batchable example:
6+
7+
```apex
8+
Database.Batchable<Object> job = new MyBatchJob();
9+
Async.AsyncResult result = new BatchableBuilder(job)
10+
.scopeSize(100)
11+
.execute();
12+
System.debug('Batch job enqueued: ' + result);
13+
```
14+
15+
## Methods
16+
17+
The following are methods for using Async with Batchable jobs:
18+
19+
[**INIT**](#init)
20+
21+
- [`batchable(Database.Batchable<Object> job)`](#batchable)
22+
23+
[**Build**](#build)
24+
25+
- [`scopeSize(Integer size)`](#scopesize)
26+
- [`minutesFromNow(Integer minutes)`](#minutesfromnow)
27+
- [`asSchedulable()`](#asschedulable)
28+
29+
[**Execute**](#execute)
30+
31+
- [`execute()`](#execute-1)
32+
33+
### INIT
34+
35+
#### batchable
36+
37+
Constructs a new BatchableBuilder instance with the specified batchable job.
38+
39+
**Signature**
40+
41+
```apex
42+
Async batchable(Database.Batchable<Object> job);
43+
```
44+
45+
**Example**
46+
47+
```apex
48+
Async.batchable(new MyBatchJob());
49+
```
50+
51+
### Build
52+
53+
#### scopeSize
54+
55+
Allows setting the scope size for the batch job.
56+
57+
**Signature**
58+
59+
```apex
60+
BatchableBuilder scopeSize(Integer size);
61+
```
62+
63+
**Example**
64+
65+
```apex
66+
Async.batchable(new MyBatchJob())
67+
.scopeSize(100);
68+
```
69+
70+
#### minutesFromNow
71+
72+
Allows scheduling the batch job to run after a specified number of minutes.
73+
74+
**Signature**
75+
76+
```apex
77+
BatchableBuilder minutesFromNow(Integer minutes);
78+
```
79+
80+
**Example**
81+
82+
```apex
83+
Async.batchable(new MyBatchJob())
84+
.minutesFromNow(10);
85+
```
86+
87+
#### asSchedulable
88+
89+
Converts the batch builder to a schedulable builder for cron-based scheduling. For scheduling, look into the [SchedulableBuilder](/api/schedulable.md) API.
90+
91+
**Signature**
92+
93+
```apex
94+
SchedulableBuilder asSchedulable();
95+
```
96+
97+
**Example**
98+
99+
```apex
100+
Async.batchable(new MyBatchJob())
101+
.asSchedulable();
102+
```
103+
104+
### Execute
105+
106+
#### execute
107+
108+
Executes the batch job with the configured options. Returns an Async.AsyncResult.
109+
110+
**Signature**
111+
112+
```apex
113+
Async.AsyncResult execute();
114+
```
115+
116+
**Example**
117+
118+
```apex
119+
Async.batchable(new MyBatchJob())
120+
.scopeSize(100)
121+
.execute();
122+
```
123+

website/api/queueable.md

Lines changed: 258 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,258 @@
1-
# Queueable
1+
# Queueable API
2+
3+
Apex classes `QueueableBuilder.cls`, `QueueableManager.cls`, and `QueueableJob.cls`.
4+
5+
Common Queueable example:
6+
7+
```apex
8+
QueueableJob job = new MyQueueableJob();
9+
Async.AsyncResult result = Async.queueable(job)
10+
.priority(5)
11+
.delay(2)
12+
.continueOnJobExecuteFail()
13+
.enqueue();
14+
System.debug('Job enqueued: ' + result.customJobId);
15+
```
16+
17+
## Methods
18+
19+
The following are methods for using Async with Queueable jobs:
20+
21+
[**INIT**](#init)
22+
23+
- [`queueable(QueueableJob job)`](#queueable)
24+
25+
[**Build**](#build)
26+
27+
- [`asyncOptions(AsyncOptions asyncOptions)`](#asyncoptions)
28+
- [`delay(Integer delay)`](#delay)
29+
- [`priority(Integer priority)`](#priority)
30+
- [`continueOnJobEnqueueFail()`](#continueonjobequeuefail)
31+
- [`continueOnJobExecuteFail()`](#continueonjobexecutefail)
32+
- [`rollbackOnJobExecuteFail()`](#rollbackonjobexecutefail)
33+
- [`asSchedulable()`](#asschedulable)
34+
35+
[**Execute**](#execute)
36+
37+
- [`enqueue()`](#enqueue)
38+
- [`attachFinalizer()`](#attachfinalizer)
39+
40+
[**Context**](#context)
41+
42+
- [`getQueueableJobContext()`](#getqueueablejobcontext)
43+
- [`getQueueableChainBatchId()`](#getqueueablechainbatchid)
44+
45+
### INIT
46+
47+
#### queueable
48+
49+
Constructs a new QueueableBuilder instance with the specified queueable job.
50+
51+
**Signature**
52+
53+
```apex
54+
Async queueable(QueueableJob job);
55+
```
56+
57+
**Example**
58+
59+
```apex
60+
Async.queueable(new MyQueueableJob());
61+
```
62+
63+
### Build
64+
65+
#### asyncOptions
66+
67+
Sets AsyncOptions for the queueable job. Cannot be used with delay().
68+
69+
**Signature**
70+
71+
```apex
72+
QueueableBuilder asyncOptions(AsyncOptions asyncOptions);
73+
```
74+
75+
**Example**
76+
77+
```apex
78+
AsyncOptions options = new AsyncOptions();
79+
Async.queueable(new MyQueueableJob())
80+
.asyncOptions(options);
81+
```
82+
83+
#### delay
84+
85+
Sets a delay in minutes before the job executes. Cannot be used with asyncOptions().
86+
87+
**Signature**
88+
89+
```apex
90+
QueueableBuilder delay(Integer delay);
91+
```
92+
93+
**Example**
94+
95+
```apex
96+
Async.queueable(new MyQueueableJob())
97+
.delay(5); // Execute in 5 minutes
98+
```
99+
100+
#### priority
101+
102+
Sets the priority for the queueable job. Lower numbers = higher priority.
103+
104+
**Signature**
105+
106+
```apex
107+
QueueableBuilder priority(Integer priority);
108+
```
109+
110+
**Example**
111+
112+
```apex
113+
Async.queueable(new MyQueueableJob())
114+
.priority(1); // High priority
115+
```
116+
117+
#### continueOnJobEnqueueFail
118+
119+
Allows the job chain to continue even if this job fails to enqueue.
120+
121+
**Signature**
122+
123+
```apex
124+
QueueableBuilder continueOnJobEnqueueFail();
125+
```
126+
127+
**Example**
128+
129+
```apex
130+
Async.queueable(new MyQueueableJob())
131+
.continueOnJobEnqueueFail();
132+
```
133+
134+
#### continueOnJobExecuteFail
135+
136+
Allows the job chain to continue even if this job fails during execution.
137+
138+
**Signature**
139+
140+
```apex
141+
QueueableBuilder continueOnJobExecuteFail();
142+
```
143+
144+
**Example**
145+
146+
```apex
147+
Async.queueable(new MyQueueableJob())
148+
.continueOnJobExecuteFail();
149+
```
150+
151+
#### rollbackOnJobExecuteFail
152+
153+
Rolls back any DML operations if this job fails during execution.
154+
155+
**Signature**
156+
157+
```apex
158+
QueueableBuilder rollbackOnJobExecuteFail();
159+
```
160+
161+
**Example**
162+
163+
```apex
164+
Async.queueable(new MyQueueableJob())
165+
.rollbackOnJobExecuteFail();
166+
```
167+
168+
#### asSchedulable
169+
170+
Converts the queueable builder to a schedulable builder for cron-based scheduling. For scheduling, look into the [SchedulableBuilder](/api/schedulable.md) API.
171+
172+
**Signature**
173+
174+
```apex
175+
SchedulableBuilder asSchedulable();
176+
```
177+
178+
**Example**
179+
180+
```apex
181+
Async.queueable(new MyQueueableJob())
182+
.asSchedulable();
183+
```
184+
185+
### Execute
186+
187+
#### enqueue
188+
189+
Enqueues the queueable job with the configured options. Returns an Async.AsyncResult.
190+
191+
**Signature**
192+
193+
```apex
194+
Async.AsyncResult enqueue();
195+
```
196+
197+
**Example**
198+
199+
```apex
200+
Async.AsyncResult result = Async.queueable(new MyQueueableJob())
201+
.priority(5)
202+
.enqueue();
203+
```
204+
205+
#### attachFinalizer
206+
207+
Attaches a finalizer job to run after the current job completes. Can only be called within a QueueableChain context.
208+
209+
**Signature**
210+
211+
```apex
212+
Async.AsyncResult attachFinalizer();
213+
```
214+
215+
**Example**
216+
217+
```apex
218+
// Inside a QueueableJob's work() method
219+
Async.queueable(new MyFinalizerJob())
220+
.attachFinalizer();
221+
```
222+
223+
### Context
224+
225+
#### getQueueableJobContext
226+
227+
Gets the current queueable job context, providing access to job information and Salesforce QueueableContext.
228+
229+
**Signature**
230+
231+
```apex
232+
Async.QueueableJobContext getQueueableJobContext();
233+
```
234+
235+
**Example**
236+
237+
```apex
238+
Async.QueueableJobContext ctx = Async.getQueueableJobContext();
239+
QueueableJob currentJob = ctx.currentJob;
240+
QueueableContext sfContext = ctx.queueableCtx;
241+
```
242+
243+
#### getQueueableChainBatchId
244+
245+
Gets the ID of the QueueableChain batch job if the current execution is part of a batch-based chain.
246+
247+
**Signature**
248+
249+
```apex
250+
Id getQueueableChainBatchId();
251+
```
252+
253+
**Example**
254+
255+
```apex
256+
Id batchId = Async.getQueueableChainBatchId();
257+
System.debug('Current batch ID: ' + batchId);
258+
```

0 commit comments

Comments
 (0)