Visualforce Remote object – I’m single

Visualforce remote object are proxy object that allows basic DML operation on sObject directly from java script. Without having any controller class we can able to retrieve, create, update, upsert and delete operations in a single visualforce page itself. Remote object call don't count towards API request limits and it supports call back functionality. This is an efficient method when creating page for use in Salesforce1 or working with libraries such as jQuery or AngularJS. Currently remote object is available as a developer preview. 

Following are two main parts of VF Remote object

Access definitions - Written in visualforce using new Remote objects components. This will create the javascript proxy object.

Data access function – Written in javascript. In this section we will perform the create, select, edit and delete operation for the proxy object record. It’s interesting right, lets have a look into each operations. 

Here is the single visualforce page(GitHub), that  will display all the contact records from your org, you can search contact based on name, edit or delete the contacts records without writing single line of apex code or any API call. 2014-08-13 16-37-40
Retrieve Record
Below is the code which will retrieve the records on the remote object, let look into that in detail. First we have to instantiate the remote object. This is common for all our DML operation method. ‘cont’ is jsShorthand for our remote object Contact.

retrieve() method on the remote object instance will fetch the records. This method accepts two arguments Criteria(where conditions) and Callback function(we need to process the retrieved records either to store or display in the page)

Create record
The Create() method on remote object instances will allow us to insert new records.Field values are set by passing in a JSON string with values for the fields to set on the new model

For updating the record call update() method and for deleting record call del() method, the logic remains same for passing the values where we need to pass ID of the record on which we need to perform update operation.

You can find the complete source code of the page in this link. To get more details on Visualforce remote object check here. Happy Coding ;)


Popular Posts