function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
SFDC LearningSFDC 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
 
Chandra Sekhar CH N VChandra Sekhar CH N V
Do you have any input for JSON data?
SFDC LearningSFDC Learning
I am just forwarding account data in destination org in body
SFDC LearningSFDC Learning
I have actually just started to work on rest api. So please can you suggest me where i am wrong in it? 

Thank you chndra sekhar
Chandra Sekhar CH N VChandra Sekhar CH N V
Its just an issue with the format you are sending your JSON response.
http://salesforce.stackexchange.com/questions/79928/trouble-executing-salesforce-web-service (https://developer.salesforce.com/forums/?id=906F0000000BVKSIA4)