1public with sharing class SampleContinuationClass {
2 // Callout endpoint as a named credential URL
3 // or, as shown here, as the long-running service URL
4 private static final String LONG_RUNNING_SERVICE_URL =
5 '<insert your callout URL here>';
6
7 // Action method
8 @AuraEnabled(continuation=true cacheable=true)
9 public static Object startRequest() {
10 // Create continuation. Argument is timeout in seconds.
11 Continuation con = new Continuation(40);
12 // Set callback method
13 con.continuationMethod='processResponse';
14 // Set state
15 con.state='Hello, World!';
16 // Create callout request
17 HttpRequest req = new HttpRequest();
18 req.setMethod('GET');
19 req.setEndpoint(LONG_RUNNING_SERVICE_URL);
20 // Add callout request to continuation
21 con.addHttpRequest(req);
22 // Return the continuation
23 return con;
24 }
25
26 // Callback method
27 @AuraEnabled(cacheable=true)
28 public static Object processResponse(List<String> labels, Object state) {
29 // Get the response by using the unique label
30 HttpResponse response = Continuation.getResponse(labels[0]);
31 // Set the result variable
32 String result = response.getBody();
33 return result;
34 }
35}