I believe that data is coming in and going out as JSON in proxy. But how is the "data" in VF controller? I dont have clarity. Please help. Visualforce controller gets a "List" of data from proxy and returns "List" of data as response. Is it converted to JSON by itself? What I really need to know is,

"Data" when in request: From proxy - JSON, To VF controller - LIST of Account(say for example).
"Data" when in response : From VF controller - LIST of Account(method returns a List), To proxy : JSON.

Is my assumption correct or wrong. If so, is conversion directly taking place? If not, what is the format?

  • 1
    Is this question about some specific code ? Elaborating more and giving some context may make this clearer to people trying to answer. Also: are all those tags truly related ? Choosing the correct tags will attrackt the right people to your question! All questions here have to be related to salesforce, so the salesforce-crm tag is redundant and shouldn't be used. – Samuel De Rycke Dec 26 '13 at 12:57
  • 1
    One for @user320 i think! ;-) – Andrew Fawcett Dec 26 '13 at 13:05
  • Sorry for the inconvenience. I am new to this and really bad at explaining things. What I really need to know is, "Data" when in request: From proxy - JSON, To VF controller - LIST of Account(say for instance). "Data" when in response : From VF controller - LIST of Account, TO proxy : JSON. Is my assumption correct or wrong. If so, is conversion directly taking place? If not, what is the format? – Lokesh Pad Dec 26 '13 at 13:22
  • Cool, can you link the proxy, show its configuration, and your apex code? – bigassforce Dec 26 '13 at 16:05

All data transmitted with JavaScript Remoting is JSON. You need never encode nor decode it. Eg:

public List<Contact> findContactsForAccount(Id accountId, String lastName) {
    return [
        SELECT Id
        FROM Contact
        WHERE AccountId = :accountId AND LastName LIKE :('%' + filter + '%')
  1. What goes up the wire is an array of the method arguments: (accountId, lastName)

    ['00100000000000A999', 'smith'] //some account id and last name
  2. What comes down the wire is the return type of the remote method, eg: (List<Contact>)

    [{Id: '003000000000001AAA'}, {Id: '003000000000002AAB'}] //contacts

This is all taken care of by the platform's remoting client and service.

Your Sencha proxy will expect certain signatures, however:

For example, a proxy for a GridPanel's flat store:

@RemoteAction List<Model__c> create(List<Model__c> models);
@RemoteAction List<Model__c> read(String filter);
@RemoteAction List<Model__c> modify(List<Model__c> models);
@RemoteAction void           destroy(List<Model__c> models);

Or a proxy for a TreePanel's hierarchical store:

@RemoteAction List<Node__c> create(List<Node__c> nodes);
@RemoteAction List<Node__c> read(Id parentId);
@RemoteAction List<Node__c> modify(List<Node__c> nodes);
@RemoteAction void          destroy(List<Node__c> nodes);

If you want the proxy to take care of the comms for you, it's up to you to offer it the services in this format. For example on your proxy's reader, you'll want to set allowSingle to false so that your service signatures are always collections (even if that's almost always a collection-of-one).

If you want to send/receive data that doesn't really fit into CRUD operations yet take advantage of the proxy, you might wrap your Request and Response up into stores whose fields hold the arguments of the commands you want to send:

An example service that isn't very CRUD:

public Map<Id,Boolean> sendEmailToAllThesePeople(List<Contact> contacts) {
    Map<Id,Boolean> statuses = new Map<Id,Boolean>();
    for (Contact contact : contacts) {
        if (...) {
            //ok to email this contact
            statuses.put(contact.Id, true);
        } else {
            //maybe this contact opted out
            statuses.put(contact.Id, false);
    return statuses;

You can 'massage' the client around it to fit:

Ext.define('My.store.EmailAttempt', {
    extend: 'Ext.data.Store',
    id: 'EmailAttempt',
    proxy: {
        type: 'vfremote',
        api: {insert: $RemoteAction.MyController.sendEmailToAllThesePeople}
        reader: {
            type: 'json',
            getData: function(statuses) {
                var rows = [];
                for (var i in statuses) {
                    //convert the 'map' into actual 'records'
                    rows.push({Id: i, Status: statuses[i]});
                return rows;
    fields: [
        {name: 'Id', type: 'string'},
        {name: 'Status', type: 'boolean'}

You get all the benefits of error handling, data binding, templating etc, your Ext application can deal in terms of models and stores, and you can invoke Ext.getStore('EmailAttempt').add(contact) in your client-side Ext controller or as appropriate.

The goal here is to configure the Sencha application into shape so that it forms the JSON expected by your services and you never see any of that going on at the transport layer.

| improve this answer | |
  • 2
    Fantastic Sencha 'native' integration with Force.com, well done! – Andrew Fawcett Dec 26 '13 at 16:46
  • @user320 , thank you again. I have one more question. How can we get fields that is children to the child fields? { "invoiceList": { "totalPrice":5.5, "statementDate":"2011-10-04T16:58:54.858Z", "lineItems":[ {"UnitPrice":1.0,"Quantity":5.0,"ProductName":"Pencil"}, {"UnitPrice":0.5,"Quantity":1.0,"ProductName":"Eraser"}], "invoiceNumber":1 } }. Any idea? – Lokesh Pad Dec 27 '13 at 10:14
  • @LokeshPad Maybe you could create a separate lineItems store, with an association field to the invoice, that you populate? Or flatten the data? – bigassforce Dec 27 '13 at 11:46
  • @user320. I have implemented it the way you have suggested. but the problem is, I have to use an existing controller(used in a normal VF page) and make it to work with proxy(make it display using sencha). So I am literally confused of how apply. – Lokesh Pad Dec 27 '13 at 13:11
  • @LokeshPad do you have any @RemoteAction annotated methods at all then? – bigassforce Dec 27 '13 at 13:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.