Insert Record using JavaScript Remoting with Visualforce Page

Insert Record using JavaScript Remoting with Visualforce Page

Hey there!

We must have heard about javascript remoting. So today we are going to learn about
how to use the Javascript remoting to build Web apps and insert the record with the
Visualforce.The DML operation directly enables for the sObject from Javascript in remote objects.
So here I am going to tell you Insert the record with visualforce page using Javascript remoting.

Here I am using the custom table and Remote object within Visualforce page:

Here is code snippet:

<apex:page id="pageId">
    <apex:remoteObjects >
        <apex:remoteObjectModel name="Account" fields="Id,Name,Industry,AccountNumber">
    var createAccount = function(){
            var Accname=document.getElementById("accname").value;
            var Accindustry=document.getElementById("accind").value;
            var Accnumber=document.getElementById("accnum").value;
            var acDetails = { Name: Accname, Industry: Accindustry,AccountNumber:Accnumber };
            var ct = new SObjectModel.Account();
            ct.create(acDetails , function(err) {
                if(err) {
                else {
                    console.log(ct.get('Id')); // Id is set when create completes
                    alert('account created successfully with id'+ct.get('Id'));
    <h1 style="font-size:20px;"><center>
        Create Account via Remote Objects
            <td>Account Name:</td><td><input type="text" name="name" id="accname"/></td>
            <td>Industry:</td><td><input type="text" name="industry" id="accind"/></td>
            <td>AccountNumber:</td><td><input type="text" name="accountNumber" id="accnum"/></td>
            <td><button onclick="createAccount()">Create Account</button></td>

How page looks:






Hope it will help you!




Leave a Reply


We're not around right now. But you can send us an email and we'll get back to you, asap.


About Us

Forcetalks is a Salesforce collaboration platform for coders & developers, geeks & nerds, consultants & business heads, admins & architects, managers & marketers and of course the business owners. A community where you can learn from, where you can contribute to. For you. For Salesforce. Read More...

Copyright 2020 Forcetalks. All Right Reserved.

Log in with your credentials


Forgot your details?