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@hicglobalsolutions.com should you have any queries in programming.

    Happy Learning!

Related Articles
Hands-On Guide Building a Drag-and-Drop Form Builder Using Lightning Web Components

Drag-and-drop interfaces are a user experience staple, and when paired with the power of Lightning Web Components (LWC), they unlock dynamic, highly interactive Salesforce components. In this blog post, we’ll walk you through how to build a custom drag-and-drop form builder in LWC. Users can drag form fields like text inputs and dropdowns into a […]

Read More
Please Make Blog Banner How to Create an Agentforce Enabled Scratch Org in Salesforce 100 1

Setting up an Agentforce-enabled scratch org is the most important step for developers who want to experiment with AI features such as Prompt Builder and Einstein GPT. Whether you’re developing the next generation CRM software or experimenting with how generative AI may improve user experience, a scratch org equipped with Agentforce is your playground. Follow […]

Read More
Step-by-Step Guide to Enhance Your LWC Development Workflow with the Logger API

Are you looking to streamline your LWC development workflow but confused about how to do it? Then you are in the right place. The Salesforce Logger API is a powerful tool that helps you monitor, debug, and improve code quality in real time.  This step-by-step guide walks you through how to set it up and […]

Read More
Enhancing Your Salesforce Experience with a Custom Activity Component

In today’s fast-paced business landscape, productivity hinges on streamlined workflows and intuitive interfaces. While Salesforce offers robust activity tracking capabilities, sometimes the standard components fall short of specific organizational needs.  That’s where a Custom Activity Component comes in—designed to tailor your activity management experience, boost user efficiency, and provide deeper insights into customer interactions. In […]

Read More
Step-by-Step Guide to Integrating Salesforce Doc-Gen with eSigning Tools

In today’s fast-paced digital landscape, streamlining document workflows is no longer a luxury—it’s a necessity.  Integrating a document generation app, like Docs Made Easy, with an eSigning tool, helps businesses automate the entire document lifecycle—from creation to signature—saving time, reducing errors, and boosting productivity. In this guide, we’ll walk you through the key steps, tools, […]

Read More
How to Build a Real Time Chat Application Using LWC and Models API

The Models API plays a significant role in providing access to and facilitating interaction with large language models (LLMs) from various Salesforce partners such as Anthropic, Google, and OpenAI. It enables applications to leverage these models for various tasks, including text generation and other AI-powered capabilities. As a user, you can configure any Salesforce-enabled model […]

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