Retrieve Accounts and Create Account via Salesforce Remote Objects

In the Spring’14 release, Salesforce had announced the support for JavaScript with its popular Visualforce Remoting feature. Visualforce Remoting was introduced to ease database operations such as create, read, update and delete in Javascript without using Apex or counting API request limits.

Used for building web apps with Visualforce, JavaScript Remoting is a popular, powerful and efficacious method. It enables the users to create pages to use in Salesforce1 or work with JavaScript libraries like jQuery or AngularJS efficiently.

Visualforce Remote Objects

Visualforce Remote Objects helps in the basic DML operations on sObjects from the JavaScript. They are the proxy objects that ease the JavaScript Remoting by cutting down the use of @RemoteAction methods in an Apex controller or extension.

Visualforce Remote Objects consists of the following:

  • Access definitions: 

Using the new Remote Objects components, Access definitions are written in Visualforce and generate a set of JavaScript proxy objects.

  • Data access functions: 

Written in JavaScript, Data Access functions use the proxy objects that are made available by the access definitions to perform create, select, update, and delete operations on the data.

For Live Demo on Create Account Using Remote Object Click Here

 

For Live Demo on Retrieve Accounts Using Remote Object Click here

Using Remote Objects in JavaScript

Remote Object Components generate Javascript models that provide JavaScript API to create functions for the apps that can read and save values back to Salesforce. One of the remote object components is <apex:remoteObjects> component that creates the base model to instantiate specific models for corresponding sObjects. These specific models enable multiple actions such as retrieving, creating, updating, and deleting to be performed on their sObjects.

The name of the base model created is sObjectModel by default and can be changed later using the jsNamespace attribute.

Basic description of Visualforce Remote Objects:-

  • Enables the user to create pages with basic data operations without content the API request limits.

  • Its tags are more suitable for Salesforce1, jQuery and AngularJS.

  • Supports basic DML operations such as Create, Read, Update and Delete in javascript without writing even a single line if apex code.

  • Controller and test classes are not required to be written anymore as it can be achieved using the Visualforce page.

Limitations of Visualforce Remote Objects

  • Though it provides new capabilities, Visualforce Remote Objects is not a complete feature yet.
  • Remote Objects have limitations of their own as they are subject to change without providing backward compatibility.
  • Remote Objects enables you to retrieve a maximum of 100 rows only in a single request. To display more records, you need to submit an 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>

Detail description above example :-

  • <apex:remoteObjects> : Used to include everything related to remote objects.
  • <apex:remoteObjectModel name=”Account” jsShorthand=”account” fields=”name”>: Used to define the object on which the DML operations will be performed.
  • jsShortHand attribute: Defines the shortcut for the object notation that can be used inside the JavaScript code.
  • “fields” attribute: Used to refer the fields to add conditions in the DML operations.

Creating Records suing 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 = { Name : ‘AAA’};

var getRecord = new RemoteModel.account();

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 suing 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 SobjectModel.account();

getRecord.retrieve( { where : name : {‘AAA’}} );

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

Create Account via Remote Object

VisualForcePage:

Retrieve Account via Remote Object VisualForcePage:

Conclusion

  • Visualforce Remote Objects are the best and lightest way to perform rapid client-side querying without impacting API limits. Here is everything you need to know about Retrieve Accounts and Create Account via Remote Objects. Please feel free to reach out to us at sales@hicstwebackup.yoursalesforcedeveloper.com should you have any queries in programming.

    Happy Learning!

Share This Blog
Related Articles

Salesforce CPQ (Configure, Price, Quote) is a powerful tool that enables businesses to streamline their quoting process by providing advanced configuration options. Among its many features, Multi-Dimensional Quoting (MDQ) stands out as a powerful capability that allows sales teams to create more detailed and flexible quotes for complex products. In this blog, we’ll dive into […]

Read More
Dynamic Search Filters in Salesforce CPQ

Salesforce CPQ (Configure, Price, Quote) is a powerful tool that allows sales teams to generate quotes with speed and accuracy. One of the key features that makes CPQ so flexible is its dynamic search filter capability. In this blog, we’ll explore how you can create dynamic search filters in Salesforce CPQ to make your quoting […]

Read More
How to Create Quote Templates Customization Methods

The objective after completing a quote is usually to produce a precise and expert quote document for clients. However, without the proper procedures in place, quoting can be difficult, error-prone, and time-consuming. Salesforce CPQ (Configure, Price, Quote) streamlines the process and improves quote accuracy by assisting with the setup and administration of quotation papers. By […]

Read More
Boost Performance with a Robust Trigger Framework in Salesforce

Boost Performance with a Robust Trigger Framework in Salesforce If you want to make sure of scalability and performance in the Salesforce development, managing Apex triggers is a must. With a trigger framework, you get a structured approach to organizing and maintaining trigger logic. This way, developers can follow the best practices while maintaining the […]

Read More

When it comes to Salesforce development, efficiently managing and deploying metadata is important to maintain streamlined operations. With the help of Unlocked Package, you can easily achieve this. It is specially designed for business’s internal use and allows businesses to develop and manage modular applications. This blog will walk you through the importance of Unlocked […]

Read More
How Salesforce Data Cloud Streamlines Data Management

The Data Cloud integrates your company’s data onto Salesforce’s Einstein 1 Platform. It provides each team with a comprehensive customer view for a better experience. The Data Cloud consolidates disparate data sources into a unified model, facilitating easy access and comprehension. It encompasses various data types such as web engagement and more from both internal […]

Read More
Our Location worldwide
Indian Flag India
3rd Floor, A-10, Pegasus Tower, Sector 68, Noida, Uttar Pradesh 201301 +91-1203117884
United States of America Flag USA
333 West Brown Deer Road Unit G – 366 Milwaukee WI, USA 53217 +1(262) 310-7818
United Kingdom Flag UK
7 Bell Yard, London, WC2A 2JR +44 20 3239 9428
Canada Canada
HIC Global Solutions INC
43 Lafferty Lane, Richmond Hill, L4C 3N8, CA +1(262) 310-7818