1

The following is the Webservice class I wrote. But I have a doubt does this serve my purpose because of the following reasons. I edited this code as per the comments and it is working .

global class VFRequestAndResponse{
   public static List<results> res;
     webservice static String requestAndResponse(string realId, blob blobMsg,Integer code, string statMsg){
         string responseVar;
         Integer respCode;
         string msg;
         res=new List<results>();
         if(realId != '' && blodMsg != '' &&  code ==0 && statMsg != ''){
            respCode= 1; // indicates the request is success
            msg = 'xyz';
            res.add(new results(respCode, msg );
         }
        return res;
    }

   public class results{
     String msg;
     Integer respCode;

    public results(Integer c, String v){
        msg = v;
        respCode = c;
    }
  }
}

I share this Webservice class wsdl with third party. They make a request with the 4 parameters as shown in the class.

1) Among these 4 parameters I have response in 2 parameters which I need to read and show on the vf page.

2)When they make a request I should update and send the other two parameters as response. Please suggest me does this possible. Brief explanation why I wrote the above weservice. When I make a request I receive acknowledge, since the actual response need time to come and when they find my requested result they call the websevice I shared.

From here my webservice come into action Therefore the thirdparty send the reponse in the request it self and expect the respond back to their request. In the later time I should capture the response I recived in a request need to be shown on vfpage

2

When writing web services / rest method you should return the response in some for of structured object (if it includes multiple parameters) You can do this using Inner class and JSON...Observe:

global class VFRequestAndResponse{

    webservice static String requestAndResponse(string realId, String blodMsg,Integer code, string statMsg){
         String responseVar;
         Integer respCode;
         string msg;

        if(realId != '' && blodMsg != '' &&  code ==0 && statMsg != ''){
            respCode= 1; // indicates the request is success
            msg = 'xyz';
            responseVar = JSON.Serialize(New Results(msg,respCode));
        }
        return responseVar;
    }


    public class results{
        String msg;
        Integer respCode;

        public results(String v, Integer c){
            msg = v;
            respCode = c;
        }
    }
}
  • I am getting the following error. Error Error: Compile Error: Illegal assignment from String to VFRequestAndResponse.results at line 11 column 13 – Suresh Sep 17 '15 at 17:01
  • Try now.............. – Eric Sep 17 '15 at 17:04
  • I think it would be better to return the results object itself and let the framework represent the two values in the XSD in the WSDL (rather than users having to also know what the JSON structure is). – Keith C Sep 17 '15 at 19:58
  • @keith good point. Easy to change to do that – Eric Sep 17 '15 at 21:42
  • @Eric I tried to make the changes as Keith said but I a getting the following error could you please correct me what I am doing wrong. I udated my question to reflect my changes. Error: Compile Error: Constructor not defined: [VFRequestAndResponse.results].<Constructor>() at line 9 column 20 – Suresh Sep 21 '15 at 17:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.