What are Visualforce Remote Objects in Salesforce?

Asked 03-Feb-2018
Viewed 807 times

1 Answer


0

In Salesforce, Remote Object is an exciting feature of Visualforce. The salesforce version Spring14 has been released the introduction of “Visualforce Remote Objects”.

In the other word, we can understand it that it is actually the replacement of JavaScript Remoting.

Now, the question occurs, what is the use of “Visualforce Remote Objects”, while we are already having the “JavaScript Remoting”?

So, here we are showing few advantages of “Visualforce Remote Objects”:
  1. By using Visualforce, there is no need to write Controllers, because everything is already done in Visualforce only.
  2. Visualforce provides @RemoteAction annotation methods, which needs to be static, so we had to take special precaution like it did not support ViewState. This hurdle is completely removed now.
  3. There is no need to write Test Class now, as no Controller is involved.
  4. Not counted against API call

So, now to start this feature under the Pilot release, we have to contact Salesforce support of the Organization. Below is the Visualforce code sample: (Assuming Querying Account Object):

Now, in the above code, new Visualforce tags are introduced like “remoteObjectModel” and “remoteObjectField“. jsShorthand attribute defines a shortcut that can be used inside our JavaScript code. Now, we don’t have to write annoying object or field name ending with “__c” or namespace name. This will keep our code tidy.

Same with Javascript code:

//Create new Remote Object Reference
var src = new SObjectModel.getActs();
//Use Remote Object to query 5 records
src.retrieve({
    limit : 10,
    where : {
         cType : {
          eq: 'Banking'
        }
    }
},
function(err,records) {
   if(err == null)
    {
         //Process returned "records" to display in Visualforce code.
    }
});

Explanation of the above code, we are calling retrieve() method of Javascript object SObjectModel. Once you get records, you can process it in your javascript. Other than retrieve(), you can perform all CRUD operations on the object.