Last active
September 9, 2020 00:08
-
-
Save victorabraham/7b0e41e1e3b6fa3bf12f4a0ee7b630e0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public with sharing class ContinuationDemo { | |
| @AuraEnabled(continuation=true cacheable=true) | |
| public static Object startContinuationRequest() { | |
| Integer timeout = 50; | |
| Continuation con = new Continuation(timeout); | |
| //Apex method to execute after getting response | |
| con.continuationMethod='processBlogResponse'; | |
| //State can be a variable of any type supported in apex | |
| con.state='Additional variable to give context. If more than one use list/set/map'; | |
| //Create Http Request | |
| HttpRequest req = new HttpRequest(); | |
| req.setMethod('GET'); | |
| //Make sure that your endpoint is added in Remote site settings | |
| req.setEndpoint('https://salesforcecodes.blogspot.com/feeds/posts/default?max-results=10&alt=json'); | |
| //Add request to continuation. Can add up to a maximum of three requests | |
| con.addHttpRequest(req); | |
| return con; | |
| } | |
| @AuraEnabled(cacheable=true) | |
| public static String processBlogResponse(List<String> labels, Object state) { | |
| // One label will be generated per request in continuation | |
| HttpResponse response = Continuation.getResponse(labels[0]); | |
| return response.getBody(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment