+ Start a Discussion
krishna 2619krishna 2619 

how to write a test class for multiple callouts

public class NumbringOrdAPI{
<br>
@auraEnabled<br>
public static string OrderApi(string ordId){<br>

  // Get Endpoint Sid 
  EndPointSid = NumberServerAPI.GetServerName(config.Server__c,authorizationHeader,metadata.Server_API_URL__c,metadata.Server_API_Method__c); <br>
<br> 
  TenentId= CallswitchTenantsAPI.getTenents(config.Tenant_ID__c,config.Server__c,authorization,metadata.Callswitch_Tenant_URL__c,metadata.Callswitch_Tenant_Method__c); 
<br>
<br>  
   if(TenentId != null && TenentId != 'Unable to Authorize to CallSwith Server' && TenentId !='Unable to find Tenent code in the server'){<br>

    flowCheck = 'End Point Sid fetched Sucessfully';<br>
   for(NumberingOrder__c numOrd : ordlst){<br>
        String jsonS = 'sid='+numOrd.Area_code_for_API__c+'&quantity='+numOrd.HowManyNumbers__c;<br>
        Http httpprotocal=new Http();<br>
        HttpRequest request=new HttpRequest();<br>
        request.setEndpoint(metadata.Order_API_URL__c);<br>           
        request.setMethod(metadata.Order_API_Method__c);<br>
        request.setHeader('Authorization','Basic '+authorizationHeader);<br>
        request.setHeader('Accept','application/json');<br>
        request.setHeader('Content-Type','application/x-www-form-urlencoded');<br>
        request.setTimeout(120000);  <br>
        request.setBody(jsonS);<br>
        system.debug('---URL----'+metadata.Order_API_URL__c);<br>
        system.debug('---Mothod----'+metadata.Order_API_Method__c);<br>
        system.debug('-------'+authorizationHeader); <br>
        system.debug('----jsonSjsonS---'+jsonS); <br>
        HttpResponse response = httpprotocal.send(request);<br>
        system.debug('Response deforder it is sent to site'+response);<br>
        System.debug('Returned result is'+response.getBody());<br>
        string res=response.getBody();<br>
         res = res.replaceFirst('number','numbers');<br>
        if(response.getStatuscode()==200 || response.getStatuscode()==201 )<br>
          {<br>
            list<NumberOrders> resobj = (list<NumberOrders>)JSON.deserialize(res,list<NumberOrders>.class);  <br>       
            system.debug('resp1 '+resobj );<br>
            if(resobj != null)<br>
            {<br>
            <br><br>
               setnumberSid = NumberServerAPI.assginedNumbers(numOrd.Area_code_for_API__c,resobj[0].sid,authorizationHeader,metadata.SetNumberURL__c,metadata.SetNumber_Mthod__c);<br>
                 <br>
               AddressSid = ZironAddressApi.PostAddress(numOrd,authorizationHeader,metadata.Installation_Address_URL__c,metadata.Installation_Address_Method__c);
                <br>
               if(resobj[0].sid != null && AddressSid != 'Error is adding Address to Ziron API')<br>
                 putAddress = ZironAddressApi.PutAddress(numOrd.sid__c,authorizationHeader,metadata.Address_to_Number_URL__c,metadata.Address_to_Number_Method__c);<br>
                else<br>
                break;<br>
            }    
        }    
     }
    } 
   }
 

This class is called from the button 

 
ShirishaShirisha (Salesforce Developers) 
Hi Krishna,

Greetings!

Please refer the sample code provided in the below blog:

https://www.quora.com/What-are-the-test-classes-for-making-multiple-callouts-in-a-single-method-in-Salesforce

Please mark it as best answer if it helps you to fix the issue.

Thank you!

Regards,
Shirisha Pathuri