Note: This release is in preview. Features described here don’t become generally available until the latest general availability date that Salesforce announces for this release. Before then, and where features are noted as beta, pilot, or developer preview, we can’t guarantee general availability within any particular time frame or at all. Make your purchase decisions only on the basis of generally available products and features.
Using Visualforce Remote Objects in JavaScript
1<apex:remoteObjects jsNamespace="MyCorpModels">
2 <apex:remoteObjectModel name="Contact" fields="FirstName,LastName"/>
3</apex:remoteObjects>
4<apex:remoteObjects jsNamespace="TrackerModels">
5 <apex:remoteObjectModel name="Shipment__c" fields="Id,TrackNum__c"/>
6</apex:remoteObjects>Specific Models
1var ct = new MyCorpModels.Contact();ct represents a specific object, Contact, and provides a connection between your page’s JavaScript and the Salesforce service. ct can be used to perform the basic “CRUD” operations—create, read, update, and delete—on contact objects in the database.
1<apex:remoteObjects jsNamespace="RemoteObjectModel">
2 <apex:remoteObjectModel name="Contact" fields="Id,FirstName,LastName,Phone">
3 <apex:remoteObjectField name="Notes__c" jsShorthand="Notes"/>
4 </apex:remoteObjectModel>
5</apex:remoteObjects>Instantiating Models and Accessing Fields
Instantiate a model with or without field values set, depending on your intent. Generally, you’ll set fields when you want to write changes to the database and omit fields when you’re just reading. Field values are set by passing in a JSON string with values for the fields to set on the new model.
1var ct = new RemoteObjectModel.Contact();1var ct = new RemoteObjectModel.Contact({
2 FirstName: "Aldo",
3 LastName: "Michaels",
4 Phone: "(415) 555-1212"
5});1var ct = new RemoteObjectModel.Contact({ FirstName: "Aldo" });
2ct.get('FirstName'); // 'Aldo'
3ct.get('Phone'); // <undefined>
4ct.set('FirstName', 'Benedict');
5ct.set('Phone', '(415) 555-1212');