+ Start a Discussion

Test class for apex class for webservice callouts

Hi All

Kindly help me here, i have an apex class for webservice, i require the test class to be completed.

The APEX CLASS is as follows;

global class Sendxxx {
    private static String workOrderId ;
    private static String workOrderStatus ;
    webService static void postToSAP(String orderStatus, String woId) { 
      If(orderStatus =='Complete' || orderStatus =='Partially Completed')
        workOrderId  = woId;
          workOrderStatus = orderStatus.tolowercase();
          //workOrderStatus = orderStatus;
  global static void getAndParse() {
        HttpRequest req = new HttpRequest();
        HttpResponse res = new HttpResponse();
        Http http = new Http();
        //String strname = 'Username';
       // String strpwd= 'pwd';
        //String SessionId = Userinfo.getSessionId();
        String strURL = System.URL.getSalesforceBaseURL().toExternalForm();
        req.setHeader('authorization','Bearer owhBgvxxxxxxz');
        req.setHeader('cache-control', 'no-cache');
        JSONGenerator gen = JSON.createGenerator(true);
            gen.writeStringField('SVMXC__Service_Order__c', workOrderId );
           gen.writeStringField('SVMXC__Order_Status__c',workOrderStatus );
          String jsonOrders = gen.getAsString();
           System.debug('jsonOrders: ' + jsonOrders);
          req.setHeader('Content-Type', 'application/json');
          req.setHeader('Accept-Encoding', 'gzip');
            req.setCompressed(true); // otherwise we hit a limit of 32000 
        try {
            res = http.send(req);
            if (res.getStatusCode() == 200 ) {
             System.debug('CALLOUOT SUCCESSFUL');
             System.debug('RESPONSE FROM CPQ 1111--->'+res.toString());
             System.debug('RESPONSE BODY--->'+res.getBody());
        catch(System.CalloutException e) {
            System.debug('Callout error: '+ e);
            System.debug('RESPONSE FROM CPQ'+res.toString());
See if this helps....
Hi Jeffrey,

I tried to go through your link, but its hard for me to get those, As im new to development .. i Kindly request you to give me a test class for that , so that i can present it to business..
Thank you.