Visualforce Remote Objects
- The Visualforce Remote Objects is a useful tool to quickly create pages with basic data operations and these do not count the API limits.
- Visualforce Remote Object tags are more suitable for Salesforce1 application.
- 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:
- There is no need for writing Controller and Test classes. Everything will be achieved using the Visualforce page.
Limitations of Visual force Remote objects:
- The default Visualforce limits still apply.
- 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>
- In the above code, the tag <apex:remoteObjects> tag is mainly used to include everything related to remote objects.
- 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.
- The jsShorthand attribute defines the shortcut for the object notation that can be used inside the JavaScript code.
- 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:
- 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:
- 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: