• Chris Baker 9
  • 0 Points
  • Member since 2015

  • Chatter
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 1
  • 1

I am trying to write a REST service which will send SF objects between Orgs. Right now, as a test, I am sending data to the same Org that it is coming from. I wrote a GET request which worked so I know the communcation part is working. But I am now trying to send an Account using POST. My JSON looks like this

    "acct": {
        "attributes": {
            "type": "Account",
            "url": "/services/data/v34.0/sobjects/Account/0018A000002ryhSQAQ"
        "Id": "0018A000002ryhSQAQ",
        "IsDeleted": false,
        "Name": "Test",
        "RecordTypeId": "012C0000000QakwIAC",
        "BillingAddress": null,
        "ShippingAddress": null,
        "OwnerId": "0058A000000I5WbQAK",
        "CreatedDate": "2015-08-25T16:07:17.000+0000",
        "CreatedById": "0058A000000I5WbQAK",
        "LastModifiedDate": "2015-08-25T16:07:17.000+0000",
        "LastModifiedById": "0058A000000I5WbQAK",
        "SystemModstamp": "2015-08-25T16:07:17.000+0000",
        "LastViewedDate": "2015-08-28T13:54:38.000+0000",
        "LastReferencedDate": "2015-08-28T21:54:40.000+0000",
        "IsPartner": false,
        "IsCustomerPortal": false,
        "Advocacy__c": false,
        "Background_check_required__c": "Criminal",
        "External_Content_Approval_Required__c": false,
        "Indicative_Data_Options__c": "Name",
        "Internal_Content_Approval_Required__c": false

**This is the service**
global with sharing class ClientMigrationService {
    static Account clientMigrated;
    global static string Migrate(Account Client) {
        //Account a = JSON.deserialize(client);
        /*Map<String, SObject> mapJsonObjects = (Map<String, SObject>)
            JSON.deserialize(Client, Map<String, SObject>.class);
        Account a= (Account) mapJsonObjects.get('Account');   
        insert a;
        clientMigrated = a;
        system.debug (client);
        return 'Success';
     public class RequestWrapper{
        Account acct;
        public RequestWrapper(){}


This is the code calling the service

public PageReference Migrate() {

        Account myAct = accountInfo ;

        system.debug('myAct = ' + myAct);

        RequestWrapper rw = new RequestWrapper();

        rw.acct = myAct;

        string myActJSON = JSON.serialize(rw);
        system.debug('myActJSON = ' + myActJSON );
        sendAccountDetails(myActJSON );
        return null;
    private string sendAccountDetails(string actDetails) {
        HttpRequest req = new HttpRequest();

        string endpoint = oauth.instance_url +'/services/apexrest/ClientMigration';
        system.debug('endpoint = ' + endpoint);

        req.setHeader('Authorization', 'OAuth '+ oauth.access_token);
        req.setHeader('content-type', 'application/json');

        Http http = new Http();

        HTTPResponse res = http.send(req);

        System.debug('BODY: '+res.getBody());



        return res.getBody();


 public class RequestWrapper{
        Account acct;
        public RequestWrapper(){}

This is the error I keep seeing
Unexpected parameter encountered during deserialization: acct at [line:1, column:10]","errorCode":"JSON_PARSER_ERROR"}]

It seems that no matter what I do it complains at the location in the JSON where it get just past the very first object and gets into the inner objects. I tried doing this without the RequestWrapper and just serializing the account directly but had the same problem. I think I must be doing something wrong with the serialization process.

Does anyone have some suggestions?

Hi everyone,


    I am a newbie to FDC (so please correct me if I am wrong anywhere) . I have gone thorugh Apex REST API and found that we can create our custom web services in Apex and expose them as REST services using Apex REST. But in most of the references it is given that we can use any programming language of our choice ( i.e. from outside FDC) to invoke this custom WS via REST API. But I want to invoke the same using Apex code (i.e., from inside FDC) via REST API.


Any help is highly appreciated

  • August 25, 2011
  • Like
  • 0