3

I have a question regarding Making an Asynchronous Callout from an adapter class that I made in apex.

Description: So i followed the Making an Asynchronous Callouts from imported WSDL guide from saleforce,(which is working fine from visual force page), but when I try to create another adapter class and call the ContinuationSOAPController.startrequest, from some reason it does not work,

 <apex:page controller="SOAPAdapter" showChat="false" showHeader="false">
   <apex:form >      
      <!-- Invokes the action method when the user clicks this button. -->
      <apex:commandButton action="{!startRequestAdapter}" 
              value="postAsynSkypeMessageTemp" reRender="result"/> 
   </apex:form>

   <!-- This output text component displays the callout response body. -->
   <apex:outputText value="{YO}" />
</apex:page>

I even tried to create a result variable in the adapter to call the response, but it still did not work.

Furthermore, the reason why im creating visual force pages is for testing purpose only, the async calls suppose to be triggered by another @invokable function, that will call this adapter and make async calls. Is there a way to use async calls not in visual force pages.

So regarding the code, its a company code, so i can not post it, but i just would like to ask how to call continoues class, from another class, it seems like it does not work.

  • No way to help you here without knowing the code behind it. All i can offer is that you have nothing with the id of result which you are saying you rerender and the output text will literally display YO. We need more information to help you with why your code is not working especially when you did not define "not working" and you did not provide the code that is causing the issue. Could you help someone if asked the same question with the same information? – Eric Dec 11 '16 at 20:53
  • Well it's more an abstract question than a specific code question, which how to use async calls not in visual force pages – zeev1079 Dec 11 '16 at 22:38
  • You call a method that executes it. Simple. If you want to check status query for it and use action polling until it is complete – Eric Dec 11 '16 at 22:39
  • Well, I have a continues object where I call the async class. And from my adapter I call the continuous object starteequest method, but from some reason I does not trigger any functionality. But if u call the continuous object for the visual force page directly it does work. – zeev1079 Dec 11 '16 at 22:46
2

Generally speaking, a Continuation requires a Visualforce page. There was a work around presented by Reggie Nair in his Dreamforce 2015 Session - Introduction To Apex Asynchronous Callout Framework, aka, Continuation at the 25 minute mark.

In most cases you would just switch to using the synchronus callout. For an Apex method marked with the @InvocableMethod annotation it makes little sense to perform an asynchronous callout as there will be no context to return the result on.

  • So if I understand correctly, there is no way to make asynchronous calls if it's not for visual force. Another alternative for making async calls is by using the @fitire and calling sync. So why did salesforce auto generate async classes if they are only for visual force – zeev1079 Dec 11 '16 at 22:37
  • It is my current understanding that Continuations are only for use within Visualforce and that there isn't currently another mechanism for asynchronous callouts to SOAP based web services. If you don't need the callout result in the same transaction then you can use @future, queueable Apex, or batch jobs. I think the reasoning is that the Apex transaction isn't going to hand around for the callout result to come back. – Daniel Ballinger Dec 11 '16 at 23:04
  • 1
    It's unfortunate, and a common source of confusion, that the async generated classes appear before the more standard callout class when they have such limited application. – Daniel Ballinger Dec 11 '16 at 23:09
  • Alright, thank you for the help, I will try to adjust my code masses on this limitations. – zeev1079 Dec 11 '16 at 23:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.