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
ashok  45ashok 45 

How to Get XML Response from the FUTURE Callout and Read the XML Response in other method?

Hi,

  Can anyone help me in this. want to get the XML response from future callout and read it from other method. please look into sample code of mine.





   @future(callout=true)
public static void calloutsample(string name,String phone)
{
 http h=new http();
 tring endPointURL='https://www.endpoint.com';
 Http req = new Http();
 HttpRequest Req=new HttpRequest();
 Req.setHeader('Content-Length', '0');
 Req.setEndpoint(endPointURL);
 Req.setMethod('POST');
 Req.setHeader('Content-Type',text/XML)            // Is this correct, i am sending xml data to external system
 Req.setbody(XMLString);
 httpresponse res=h.send(Req);
 xmlStreamReader reader=res.getxmlStreamReader();
 readresponse(reader);                             //Is this correct. this is the method to read the xml response 
 
}

public void readresponse(reader)
{
 //want to read the xml response here, based on the response want to perform some actions.
}
Best Answer chosen by ashok 45
pconpcon
You can do what you want but you'll need to modify your method definition
 
public static void readResponse(XmlStreamReader reader) {
    // Code
}

Then you just call it the same way you are above.

You setHeader is close but you'll want
 
req.setHeader('Content-Type', 'text/xml');

The content type should be all lower case.

All Answers

pconpcon
You can do what you want but you'll need to modify your method definition
 
public static void readResponse(XmlStreamReader reader) {
    // Code
}

Then you just call it the same way you are above.

You setHeader is close but you'll want
 
req.setHeader('Content-Type', 'text/xml');

The content type should be all lower case.
This was selected as the best answer
ashok  45ashok 45
Thanks pcon,

​     here Iam having one more doubt, can we pass colletion of callections in future callout method.

    for example :
     
               @future(callout=true)
                public static void calloutsample(string name,String phone,map<String,map<string,string>> mapvalues)
               
                    (OR)

               @future(callout=true)
                public static void calloutsample(string name,String phone,map<map<string,string>,<String,string>> mapvalues)
    
  In my mapvalues am storing request values and want to save transaction data(request) it into salesforce object but it is not supporting. can you give any idea on this.
pconpcon
You cannot pass anything but primatives and lists/sets of primatives.  What you can do however is convert your Map to a String using JSON.serialize [1] and then once your method starts turn it back into a map with JSON.deserialize [2].

[1] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm#apex_System_Json_serialize
[2] https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_class_System_Json.htm#apex_System_Json_deserializeUntyped