+ Start a Discussion
Swamy P R NSwamy P R N 

how to get response from external system

Hi Folks,

Am sending json format data to external system,its invoking fine.But am not able to get the response from that system.When am trying with workbench or advanced rest client(Google) its giving response properly.

But i was not able to get the response to the instance which i used(salesforce).

Here is my code : Sending Data to Extrnal sys

webService static void callExternalsysAndUpdatereward(string body){
        Http h = new Http();
         HttpRequest req = new HttpRequest();
            system.debug('Reward Data '+body);   
           // Send the request, and return a response
         HttpResponse res = h.send(req);
         system.debug('HttpResponse res '+res.getbody());

in other system its invoking  properly .Class :

global class cls_RecieveAndSend_DatatoSrisys

    global static MyUserDefinedClass doPost()
        RestRequest req = RestContext.request;
        System.debug('req  Body '+req);
        RestResponse res = RestContext.response;
        string strJSON = req.requestBody.toString();
           System.debug('Json O/P is '+strJSON);
        JSONparser parser = JSON.createParser(strJSON);    
        Type reqObj = Type.forName('cls_ReceivingSupport');       
        cls_ReceivingSupport rewCls=(cls_ReceivingSupport)parser.readValueAs(reqObj);
        MyUserDefinedClass My=new MyUserDefinedClass();
        if(rewCls.month==null && rewCls.year!=null && rewCls.empid!=null){
            User u = [select id,name from user where Emp_Id__c=:rewCls.empid];
            System.Debug('Users Name :'+u.Name);
            Reward__c r = [select id,name,Time_Based_Mgmnt__c,Cut_off_Percent__c,Active__c,Rward_Amount__c,User__c from Reward__c where ((User__c=:u.id) AND (CALENDAR_YEAR(Time_Based_Mgmnt__r.Start_Date__c)=:rewCls.year))];
           JSONGenerator gen = JSON.createGenerator(true);
                  gen.writeNumberField('Reward Amount',r.Rward_Amount__c);
                  gen.writeStringField('Period Data',r.Time_Based_Mgmnt__c);
                  gen.writeStringField('User Data',r.User__c);
                String jsonString = gen.getAsString();
                System.Debug('Json O/P is '+jsonString);
                My.Data='Rewards List is '+jsonString;
        System.Debug('Json O/P My '+My);
      return My;
    global class MyUserDefinedClass {     
        global String Data;      
        //global String Amount;
        global string Status;

sending is success to another system,that system is invoking properly but am not able to get the response in first system. can anyone suggest me on this.
Swamy P R NSwamy P R N
Am integrating this with salesforce-salesforce only using Rest Resource.Any idea guys...:)