Skip to content

Instantly share code, notes, and snippets.

@ayub-ansari
Last active December 26, 2018 05:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayub-ansari/adc1a1b5b4fb8e763d7c2e87f46a10c8 to your computer and use it in GitHub Desktop.
Save ayub-ansari/adc1a1b5b4fb8e763d7c2e87f46a10c8 to your computer and use it in GitHub Desktop.
global class CalloutController{
public static String requestLabel;
@RemoteAction
public static Object helpSupportAgents(String body){
Map<String, Object> jsonPayload = new jsonPayload()
jsonPayload.put('searchKeyword', body);
String endpoint = '<long running callout endpoint>';//I can not provide url due to security issue
Continuation searchContinuation = makeContinuation('callbackMethod', 'POST', endpoint, JSON.serialize(jsonPayload));
searchContinuation.state = searchContinuation.addHttpRequest(req);
return searchContinuation;
}
public static Object callbackMethod(Object state){
HttpResponse res = Continuation.getResponse((String)state);
return res.getBody();
}
public static Continuation makeContinuation(String contMethodName, String method, String endpoint, String requestPayload){
Continuation searchContinuation = new Continuation(120);
searchContinuation.continuationMethod = contMethodName;
HttpRequest req = new HttpRequest();
req.setMethod(method);
req.setEndpoint(endpoint);
req.setBody(requestPayload);
req.setHeader('content-type','application/json');
searchContinuation.state = searchContinuation.addHttpRequest(req);
requestLabel = searchContinuation.state;
return searchContinuation;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment