You need to sign in to do that
Don't have an account?
SFDC Learning
Issue when integration ( Salesforce to Salesforce) using Rest API
My apex class :
public class fatchAccountRecords{
public static String fetchAccounts(){
string strSessionid = loginsalesforce.login();
HttpRequest req = new HttpRequest();
//String strEndpointURL = 'https://na15.salesforce.com/services/apexrest/BoxRecords';
String strEndpointURL = 'https://111-dev-ed.my.salesforce.com/services/apexrest/Account';
req.setEndpoint(strEndpointURL);
req.setMethod('GET');
Account acc=[select id,name,phone,website from account where id='0019000001nz3Zq'];
String naame=acc.name;
req.setBody('<?xml version="1.0" encoding="UTF-8"?><request><name>'+ naame +'</name></request>');
system.debug('ssssssssssssssssssss'+req.getbody());
//req.setBody('');
req.setTimeout(60000);
req.setHeader('Authorization','Bearer '+strSessionid );
req.setHeader('Content-Type', 'application/json; charset=UTF-8');
HttpResponse res = new Http().send(req);
system.debug('response'+ res);
system.debug('response'+ res.getBody());
return res.getBody();
}
}
On destination org APEX class:
@RestResource(urlMapping='/Account/*')
global with sharing class MyRestResource {
@HttpPost
global static String doPost(String name) {
Account account = new Account();
account.Name = name;
// account.phone = phone;
// account.website = website;
insert account;
return account.Id;
}
}
It is giving the15:46:12:444 USER_DEBUG [25]|DEBUG|response[{"message":"Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:1, column:2]","errorCode":"JSON_PARSER_ERROR"}]
Thanks in advance
public class fatchAccountRecords{
public static String fetchAccounts(){
string strSessionid = loginsalesforce.login();
HttpRequest req = new HttpRequest();
//String strEndpointURL = 'https://na15.salesforce.com/services/apexrest/BoxRecords';
String strEndpointURL = 'https://111-dev-ed.my.salesforce.com/services/apexrest/Account';
req.setEndpoint(strEndpointURL);
req.setMethod('GET');
Account acc=[select id,name,phone,website from account where id='0019000001nz3Zq'];
String naame=acc.name;
req.setBody('<?xml version="1.0" encoding="UTF-8"?><request><name>'+ naame +'</name></request>');
system.debug('ssssssssssssssssssss'+req.getbody());
//req.setBody('');
req.setTimeout(60000);
req.setHeader('Authorization','Bearer '+strSessionid );
req.setHeader('Content-Type', 'application/json; charset=UTF-8');
HttpResponse res = new Http().send(req);
system.debug('response'+ res);
system.debug('response'+ res.getBody());
return res.getBody();
}
}
On destination org APEX class:
@RestResource(urlMapping='/Account/*')
global with sharing class MyRestResource {
@HttpPost
global static String doPost(String name) {
Account account = new Account();
account.Name = name;
// account.phone = phone;
// account.website = website;
insert account;
return account.Id;
}
}
It is giving the15:46:12:444 USER_DEBUG [25]|DEBUG|response[{"message":"Unexpected character ('<' (code 60)): expected a valid value (number, String, array, object, 'true', 'false' or 'null') at [line:1, column:2]","errorCode":"JSON_PARSER_ERROR"}]
Thanks in advance
Thank you chndra sekhar
http://salesforce.stackexchange.com/questions/79928/trouble-executing-salesforce-web-service (https://developer.salesforce.com/forums/?id=906F0000000BVKSIA4)