function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sgkmillssgkmills 

How to use Asynchronous Callout to process XML Data

Good Day All, I have written a class in Apex that has a bunch of methods, some are used to do Callouts to a 3rd party RESTful Web service and some are used to parse the XML data that is returned by the RESTful Web service. The Callout is instantiated by a user clicking a button on a Visual Force Page. The button resides on a page layout of a custom object, 'IOC'. A string is composed of data from the 'IOC' object and its children, 'IR' object. This string is passed to the callout, which processes it and returns XML data. The Callout works fine, I am able to parse the XML data returned with the methods I wrote and am able to update fields in a custom object after the XML data is parsed. The issue is that the Callout can take anywhere from 30-120 seconds when the 'IOC' object has more than 50 'IR' objects. This is too long for a user to be waiting for the data to be returned. So I wrote an Asynchronous Callout to alleviate the problem which sends the data over to the 3rd party RESTful Web service service in batches. The issue is that the Asynchronous Callout doesn't have a return value and is marked as 'static' and my methods that are parsing the XML data are marked as 'public virtual'. This seems to not allow me to call the parsing methods from within the Asynchronous Callout Method. Am I able to use the methods I created to parse the XML data from withing the Asynchronous Callout Method? If not, what is the best approach to process the XML data using an Asynchronous Callout method. BTW, the Asynchronous Callout method does make the Callout to the 3rd party RESTful Web service. I tested it with an 'IOC' object of 200 'IR' objects and the Asynchronous Callout method ran 4 separate times because it makes a callout in batches of 50 'IR' objects. I went into the monitoring area of Salesforce and saw each Asynchronous Callout method had a status value of 'Success' and looked at the log file and saw that the Callout was made successful and the XML data was returned by the Web service. Now I just need to be able to use the parsing methods I created to parse the data. So close!!!! Any information would be greatly appreciated, links, sample code, etc.... Thanks in advance