Is it possible to include these fields Id,Name,Description__c in a Remote Objects definition within a Visualforce Page without hardcoding them? I would like to pass them from elsewhere and am exploring how to do that.

<apex:remoteObjects >
<apex:remoteObjectModel jsShortHand="rObjModelJsSH" name="customObject__c" fields="Id,Name,Description__c">            
    <apex:remoteObjectField name="relationship__c" jsShorthand="Parent" />


1 Answer 1


The obvious way to try this is to set the fields list to a Visualforce expression. Unfortunately, although that does compile, it doesn't work:

<apex:remoteObjects jsNamespace="Test">
    <apex:remoteObjectModel name="Account" fields="{! fieldList }">            

You get back the Id only when you perform a retrieve.

However, you can do this with a remote objects action override.

Visualforce Page

<apex:page controller="TestRemoteActionOverrideController">
    <apex:remoteObjects jsNamespace="Test">
        <apex:remoteObjectModel name="Account" fields="Id"
                                retrieve="{! $RemoteAction.TestRemoteActionOverrideController.retrieve }" />            
        var act = new Test.Account();
            { },
            function(error, results, event) {
                alert('Got results: ' + JSON.stringify(results) + ' Error was: ' + error);

Apex Controller

public class TestRemoteActionOverrideController{
    public static Map<String,Object> retrieve(String type, List<String> fields, Map<String, Object> criteria) {

        // call through to the default remote object controller with our modified field list.
        return RemoteObjectController.retrieve(type, fields, criteria);

If you load this page, you'll find both the Name and Id fields populated in the alert message. You can, if necessary, override other remote actions accordingly.


You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .