Activity Forums Salesforce® Discussions How to insert record on sobject using visualforce page without using controller?

  • How to insert record on sobject using visualforce page without using controller?

  • Parul

    August 17, 2018 at 7:17 am

    How to insert record on sobject using visualforce page without using controller?

  • shradha jain

    August 21, 2018 at 9:56 am

    Hello Parul,

    You can use remote objects to insert a record on sobject using visualforce page without using controller. Remote Objects are proxy objects that enable basic DML operations on sObjects directly from JavaScript.All of the data access is handled by the Remote Objects components.


    This Visualforce page retrieves a list of 10 Warehouse records and displays them on the page in response to the user clicking the Retrieve Warehouses button.

    <!-- Remote Objects definition to set accessible sObjects and fields -->
    <apex:remoteObjects >
    <apex:remoteObjectModel name="Warehouse__c" jsShorthand="Warehouse"
    <apex:remoteObjectField name="Phone__c" jsShorthand="Phone"/>

    <!-- JavaScript to make Remote Objects calls -->
    var fetchWarehouses = function(){
    // Create a new Remote Object
    var wh = new SObjectModel.Warehouse();

    // Use the Remote Object to query for 10 warehouse records
    wh.retrieve({ limit: 10 }, function(err, records, event){
    if(err) {
    else {
    var ul = document.getElementById("warehousesList");
    records.forEach(function(record) {
    // Build the text for a warehouse line item
    var whText = record.get("Name");
    whText += " -- ";
    whText += record.get("Phone");

    // Add the line item to the warehouses list
    var li = document.createElement("li");

    <h1>Retrieve Warehouses via Remote Objects</h1>


    <ul id="warehousesList">
    <button onclick="fetchWarehouses()">Retrieve Warehouses</button>


    You can refer the following link for more information:


  • shariq

    September 16, 2018 at 1:02 pm


    Try this -

    <apex:page id=”pageId”>

    <script src=”/soap/ajax/20.0/connection.js” type=”text/javascript”></script>


    function insertAccount(){

    //Getting Session ID.

    sforce.connection.sessionId= “{!$Api.Session_ID}”;

    //Creating New Account Record.

    var account = new sforce.SObject(“Account”);

    //Getting Account Name from inputText.

    account.Name = document.getElementById(“pageId:frm:pb:pbs:pbsi:txtName”).value;

    //Create method

    var result = sforce.connection.create([account]);

    //Getting result

    if(result[0].getBoolean(“success”)) {

    alert(“New Account is created with id ” + result[0].id);



    alert(“failed to create new Account ” + result[0]);




    <apex:form id=”frm”>

    <apex:pageBlock title=”Insert Account” tabStyle=”Account” id=”pb”>

    <apex:pageBlockSection title=”Account Name” columns=”1″ id=”pbs”>

    <apex:pageBlockSectionItem id=”pbsi”>

    <apex:outputLabel value=”Name” />

    <apex:inputText title=”Name” id=”txtName” />




    <apex:commandButton onclick=”return insertAccount();” value=”Save”/>





    Hope his helps.

Viewing 1 - 3 of 3 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos