Newer Version Available
Aura Component Continuations Example
Here’s the markup for a component with a button that starts the process of calling a
continuation.
The component is wired to the Apex class that uses a continuation by setting the controller attribute in the <aura:component> tag.
1<aura:component controller="SampleContinuationClass">
2 <lightning:button label="Call Continuation" onclick="{!c.callContinuation}"/>
3</aura:component>Here’s the component’s JavaScript controller. The code calls the startRequest Apex method that uses a Continuation object. The response.getReturnValue() value for a successful response in the JavScript controller corresponds to the value returned by the Apex callback method defined in the Continuation object.
1({
2 callContinuation : function(cmp) {
3 var action = cmp.get("c.startRequest");
4 action.setCallback(this, function(response) {
5 var state = response.getState();
6 if (state === "SUCCESS") {
7 console.log("From server: "
8 + response.getReturnValue()
9 + '\n' + JSON.stringify(response.getReturnValue()));
10 }
11 else if (state === "INCOMPLETE") {
12 alert("Continuation action is INCOMPLETE");
13 }
14 else if (state === "ERROR") {
15 var errors = response.getError();
16 if (errors) {
17 if (errors[0] && errors[0].message) {
18 console.log("Error message: " +
19 errors[0].message);
20 }
21 } else {
22 console.log("Unknown error");
23 }
24 }
25 });
26 // Enqueue action that returns a continuation
27 $A.enqueueAction(action);
28 }
29})This JavaScript controller code is similar to any other component that calls an Apex method.