You need to sign in to do that
Don't have an account?

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();
req.setEndpoint('xxxxxxxxxxx');
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
req.setBody(body);
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 :
@RestResource(urlmapping='/RewardSearch_and_Send/*')
global class cls_RecieveAndSend_DatatoSrisys
{
@HttpPost
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.writeStartObject();
gen.writeStringField('Name',r.Name);
gen.writeNumberField('Reward Amount',r.Rward_Amount__c);
gen.writeNumberField('Cut-Off',r.Cut_off_Percent__c);
gen.writeStringField('Period Data',r.Time_Based_Mgmnt__c);
gen.writeStringField('User Data',r.User__c);
gen.writeBooleanField('Active',r.Active__c);
gen.writeEndObject();
String jsonString = gen.getAsString();
System.Debug('Json O/P is '+jsonString);
My.Data='Rewards List is '+jsonString;
My.Status='Success';
}
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.
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();
req.setEndpoint('xxxxxxxxxxx');
req.setMethod('POST');
req.setHeader('Content-Type','application/json');
req.setBody(body);
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 :
@RestResource(urlmapping='/RewardSearch_and_Send/*')
global class cls_RecieveAndSend_DatatoSrisys
{
@HttpPost
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.writeStartObject();
gen.writeStringField('Name',r.Name);
gen.writeNumberField('Reward Amount',r.Rward_Amount__c);
gen.writeNumberField('Cut-Off',r.Cut_off_Percent__c);
gen.writeStringField('Period Data',r.Time_Based_Mgmnt__c);
gen.writeStringField('User Data',r.User__c);
gen.writeBooleanField('Active',r.Active__c);
gen.writeEndObject();
String jsonString = gen.getAsString();
System.Debug('Json O/P is '+jsonString);
My.Data='Rewards List is '+jsonString;
My.Status='Success';
}
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.

Am integrating this with salesforce-salesforce only using Rest Resource.Any idea guys...:)