You need to sign in to do that
Don't have an account?

Callback method in continuation method is not getting invoked
I have a requirement wherein I have to make a callout upon Pageload.
The continuation request method is getting invoked, but not the callback.
The response is not getting displayed.
Steps to replicate the same:
1) I'm calling a controller method from action attribute of <apex:page>
2) From that method I'm calling the continuation method.
3) For some reason, But the call back method is not getting invoked.
PS: The same thing is working if I call from a command button with render attribue
Any help/pointers would be highly appreciated.
Many Thanks!
The continuation request method is getting invoked, but not the callback.
The response is not getting displayed.
Steps to replicate the same:
1) I'm calling a controller method from action attribute of <apex:page>
2) From that method I'm calling the continuation method.
3) For some reason, But the call back method is not getting invoked.
PS: The same thing is working if I call from a command button with render attribue
Any help/pointers would be highly appreciated.
Many Thanks!
Could you please post your code snippet so that we can just have a look which methods you are calling from your visual force page and possibly suggest you some pointers accordingly.
Best Regards,
Nagendra.P
If I invoke the startRequest method directly the response is coming.
If I try to invoke method1 first & through that if I invoke startRequest, the callback method is not getting invoked.
The actual code is very big, I tried to simplify it as much as possible.
The design is such we cannot call the continuation method directly. So looking for ways of invoking it.
Many thanks!
Here is the code:
VF Page
<apex:page controller="continuationController" action="{!method1}">
<apex:form >
<apex:pageBlock title="Continuation Demo">
<!-- <apex:commandButton action="{!startRequest}" value="Request Service" reRender="responseBlock"/> -->
</apex:pageBlock>
<apex:pageBlock title="Response from Webservice" id="responseBlock">
{!result}
</apex:pageBlock>
</apex:form>
</apex:page>
Controller
public class continuationController{
//Variables
public String requestLabel;
public String result {get;set;}
//Method1
public void method1(){
startRequest();
}
// Action method
public Object startRequest() {
// Create continuation with a timeout
Continuation con = new Continuation(40);
// Set callback method
con.continuationMethod='processResponse';
// Create callout request
HttpRequest req = new HttpRequest();
req.setEndpoint(EndPoint); //ENDPOINT URL
req.setMethod('POST'); //TYPE OF METHOD
req.setBody(jsonReqBody);
req.setHeader('Authorization', AuthorizationToken);
req.setHeader('Content-Type','application/json');
// Add callout request to continuation requestLabel = con.addHttpRequest(req);
system.debug('@@ requestLabel'+requestLabel);
// Return the continuation
return con;
}
// Callback method
public Object processResponse() {
HttpResponse response = Continuation.getResponse(requestLabel);
system.debug('@@response'+response);
result = response.getBody();
system.debug('@@ this.result'+result);
// Return null to re-render the original Visualforce page
return null;
}
}
I was also facing the issue of callback method not getting invoked. After few hours of trial and error methods following is my conclusion -
1. Your page needs to have some part to reRender e.g. <apex:outputPanel>
2. also, inside <apex:outputPanel> you should access the some variable referred in controller which will have its value changed in the callback method. (If you just have <apex:outputPanel> and do not add anything inside it then callback WILL NOT INVOKED.
see following code -
in above code
1. csvPanel is being reRendered.
2. if you do not put any <apex:repeat> then the callback will not be invoked. But if you put <apex:repeat> (as shown in the above code) then callback method is invoked.
This is strange behaviour but it worked for me.
Hope this will help others.
P.S. - Continuation callback is invoked only when a continuation is initialised from Visualforce only. It will not work if continuation is initiated by any Apex.