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
prasanth sfdcprasanth sfdc 

rest api with salesforce to salesforce thowing error

rest api with salesforce to salesforce thowing error. 

Class.System.JSON.deserialize: line 15, column 1 Class.SendAccountFromSource.createAccount: line 53, column 1 02:22:18.32 (551178169)|FATAL_ERROR|System.JSONException: Malformed JSON: Expected '{' at the beginning of object


This is my apex code. here line no.53 error is showing. please help
public class SendAccountFromSource {
 private final String clientId = '3MVG9ZL0ppGP5UrCXwgNBMST50Qgzy25yEBImbav2qxNHYZumcKbMK09kOK5qvYnGpde4jJt.MtQ1rjlyytaP';
 private final String clientSecret = '7453209643147176840';
 private final String username = 'prasanthkumar@gmail.com';
 private final String password = 'dolly1234';
 
 
 public class deserializeResponse
 {
  public String id;
  public String access_token;
 }
 
 
 public String ReturnAccessToken (SendAccountFromSource acount)
 {
  String reqbody = 'grant_type=password&client_id='+clientId+'&client_secret='+clientSecret+'&username='+username+'&password='+password;
  Http h = new Http();
  HttpRequest req = new HttpRequest();
  req.setBody(reqbody);
  req.setMethod('POST');
  req.setEndpoint('https://login.salesforce.com/services/oauth2/token');
  HttpResponse res = h.send(req);
  deserializeResponse resp1 = (deserializeResponse)JSON.deserialize(res.getbody(),deserializeResponse.class);
  
  system.debug('The resp1.access_token is : ' +resp1.access_token+' The status code is: '+res.getstatuscode() +'....' +res.getstatus());
  
  
  return resp1.access_token;
  
  
 }
 @future(callout=true)
 public static void createAccount(String accName, String accId) 
 {
  SendAccountFromSource acount = new SendAccountFromSource();
  String accessToken = acount.ReturnAccessToken (acount);
 
  if(accessToken != null)
  {
  system.debug('inside the if statement :' );
   String endPoint = 'https://ap2.salesforce.com/services/apexrest/v1/createAccount/';
   String jsonstr = '{"Name" : "' + accName + '"}';
   Http h2 = new Http();
   HttpRequest req1 = new HttpRequest();
   req1.setHeader('Authorization','Bearer ' + accessToken);
   req1.setHeader('Content-Type','application/json');
   req1.setHeader('accept','application/json');
   req1.setBody(jsonstr);
   req1.setMethod('POST');
   req1.setEndpoint(endPoint);
   HttpResponse res1 = h2.send(req1);
   deserializeResponse resp2 = (deserializeResponse)JSON.deserialize(res1.getbody(),deserializeResponse.class);
   Account a = [SELECT Id FROM Account WHERE Id = :accId];
   a.externalId__c = resp2.id;
   update a;
  }
 }
}

 
salesforceMannsalesforceMann
Hi, could you paste the result of system.debug (res1.getbody());