You are using an older browser that might negatively affect how this site is displayed. Please update to a modern browser to have a better experience. Sorry for the inconvenience!

Visualforce Remote Objects


By: Radha

Visualforce Remote Objects 

  1. The Visualforce Remote Objects is a useful tool to quickly create pages with basic data operations and these do not count the API limits.
  2. Visualforce Remote Object tags are more suitable for Salesforce1 application.
  3. The Visualforce remote objects supports basic DML operations such as Create, Read, Update and Delete in javascript without writing even a single line of apex code.

Click Salesforce: Visualforce Remote Objects to get more details about Visualforce remote objects.

Asset of Visualforce Remote objects:

  1. There is no need for writing Controller and Test classes. Everything will be achieved using the Visualforce page.

Limitations of Visual force Remote objects:

  1. The default Visualforce limits still apply.
  2. You can retrieve a maximum of 100 rows in a single request. To display more records, submit additional request by using the OFFSET query parameter.

Example:

<apex:remoteObjects>
<apex:remoteObjectModel name="Account" jsShorthand="account" fields="Name,Id,FirstName,LastName,Phone,Rating">
</apex:remoteObjectModel>
</apex:remoteObjects>

 

 

  1. In the above code, the tag <apex:remoteObjects> tag is mainly used to include everything related to remote objects.
  2. The <apex:remoteObjectModel name=”Account” jsShorthand=”account” fields=”name”> tag is being used to define the object on which the DML operations will be performed.
  3. The jsShorthand attribute defines the shortcut for the object notation that can be used inside the JavaScript code.
  4. The “fields” attribute is used to refer the fields, if you need to add some conditions in your DML operations.

 

 

Creating Records using Remote objects:

  1. create() is used to create a record on a Remote object instance.

RemoteObjectModel.create({field values}, Callback function}

The field values block defines the record to create in one statement.

Example:

var createRecord = { FirstName : ‘AAA’ , lastName : ‘BBB’};
var getRecord = new RemoteObjectModel.Contact();
getRecord.create(createRecord);

create() does not return a result directly. Callback function is used to handle the server response.

 

Retrieve Records using Remote Objects:

  1. We can retrieve the record using the retrieve() function in remote object.
var getRecord = new SobjectModel.account();

First we need to initialize the remote objects and it is applicable for our DML operation method.

Example:

var getRecord = new RemoteObjectModel.Contact();
getRecord.retrieve ({where : firstname : {‘AAA’}} ;

retrieve() doesnot return a result directly. The callback function enables you to handle the server response.

To get more details about Visualforce Remote object, follow the links below:

Visualforce Remote Objects

Remote Objects Callback Functions

Best Practices for using Remote Objects