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
Nishad BashaNishad Basha 

how to write the future (callout=true) in test classes with examples in salesforce?

can you please give me the examples above scenario.
Nishad BashaNishad Basha
public class Futureapexcallout{

  @future(Callout=true)
  public static void apexcallout(string billingstate,string billingcity,Id AccountId){
    
     // Instantiate a new http object
    Http h = new Http();
    
    // Instantiate a new HTTP request, specify the method (GET) as well as the endpoint
    HttpRequest req = new HttpRequest();
    String requestURL='http://api.wunderground.com/api/551013da52923e43/conditions/q/';
    requestURL=requestURL+billingstate+'/'+billingcity+'.json';
    req.setEndpoint(requestURL);
    req.setMethod('GET');

   // Send the request, and return a response
    HttpResponse res = h.send(req);
    string result=res.getBody();
    system.debug('^^^^^^'+result);
    WeatherInfo weatherinformation=new WeatherInfo();
    WeatherInfo.Current_observation currentobserv=new WeatherInfo.Current_observation();
    WeatherInfo.Display_location location=new WeatherInfo.Display_location();
    weatherinformation=(WeatherInfo)JSON.deserialize(result, WeatherInfo.class);
    currentobserv=weatherinformation.Current_observation;
    location=currentobserv.display_location;
    Account accupdate=[Select BillingPostalcode from Account where Id=:AccountId];
    accupdate.BillingPostalcode=location.zip;
    update accupdate;
  }

}

How to write the  test class for above code.plase give some ideas.
Ray KaushikRay Kaushik
Hi Nishad,

This will be actually very simple. Code will be something like this - 
 
Test.startTest();

myClass.futuremethod( someID );

Test.stopTest();

Do refer to this link for further details - https://developer.salesforce.com/forums/?id=906F000000094QOIAY

Let me know if it helps.

Thanks,
Ray
Nishad BashaNishad Basha

hi, kaushik ray 1
 how to write the above code for complete test class please give some ideas.