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
sheetal_acssheetal_acs 

Read XML using HttpRequest is not working

Unable to fetch the data.

public class AccountUpdater {

  //Future annotation to mark the method as async.
  @Future(callout=true)
  public static void updateAccount(String id, String name) {

    //construct an HTTP request
    HttpRequest req = new HttpRequest();
    req.setEndpoint('http://cheenath.com/tutorial/sfdc/sample1/data.txt');
    req.setMethod('GET');

    //send the request
    Http http = new Http();
    HttpResponse res = http.send(req);

    //check the response
    if (res.getStatusCode() == 200) {

      //update account
      Account acc = new Account(Id=id);
      acc.Description = res.getBody();
      update acc;
    } else {
      System.debug('Callout failed: ' + res);
    } 
  }
}

 Description is blank. I have used trigger to call this class. and also have added the URL in Remote site. I have checked  Apex Job,it shows job status Completed. I am trying from developer account

Best Answer chosen by Admin (Salesforce Developers) 
Ispita_NavatarIspita_Navatar

Hi,

 

First of all you have to check in debug window what you are getting the account id for update the records.

 

                //check the response

                if (res.getStatusCode() == 200)

                {

                                system.debug( ' Account ID'  +  id);

                                Account acc = new Account(Id=id);

                                acc.Description = res.getBody();

                                update acc;

                }

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.