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
siddartha reddy kalamsiddartha reddy kalam 

Test class for http callout

Hello everyone, I need help in writitng a test class for below code.

public with Sharing class DAP_ConcurQueueAccounts 
{
 public class Output{
        
        @InvocableVariable(required= true)
     public Integer statusCode;}
    
  public class Input{
        @InvocableVariable(required= false)
        public string account;
        
        @InvocableVariable(required= false)
        public decimal lastmod;
        
        @InvocableVariable(required= false)
        public string resource;
        
        @InvocableVariable(required= false)
        public integer maxItems;
    }
   @InvocableMethod
    public static List<Output> queueAccounts(List<Input> input )
    {
         List<Output> statuscodeoutput = new List<Output>();
        for(Input queaccinput : input)
        {
             // JK Renamed output variable
             Output out = new Output();
             
             System.debug('account: ' + queaccinput.account);
             System.debug('lastmod: ' + queaccinput.lastmod);
             System.debug('resource: ' + queaccinput.resource);
             System.debug('maxItems: ' + queaccinput.maxitems);
            
            Long startTimeLong = DateTime.now().getTime();
             System.debug('Start time: ' + startTimeLong);
             
             String bodyString = 'account='+queaccinput.account+'&lastmod='+queaccinput.lastmod;
             System.debug('Account & lastmod params: ' + bodyString);
            
         
             HttpRequest req = new HttpRequest();
             req.setEndpoint('callout:xyz.com');
             req.setMethod('POST');
             req.setTimeout(9000);
             
req.setBody(bodyString);
            
             Http http = new Http();
             HTTPResponse res = http.send(req);
            
             out.statusCode = res.getStatusCode();
             statuscodeoutput.add(out);
            
             
             System.debug('Response status code: ' + res.getStatusCode());
            
      
        }
     return  statuscodeoutput; 
    }
}
Sunil SirangiSunil Sirangi

@Siddartha reddy kalam: Please let me know where you are stuck with the test class. Please post what you have written in your test class so that we can help you. If you are a beginner and want to write test class please do follow below links.

Trail Head (https://trailhead.salesforce.com/en/content/learn/modules/apex_testing/apex_testing_intro)

Salesforce Documentation (https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm)

SFDC99 Blog (http://www.sfdc99.com/2013/05/14/how-to-write-a-test-class/)

siddartha reddy kalamsiddartha reddy kalam
@sunil sirangi. Thanks for the reply. I found my error and currently its working fine.
Thanks