Creator Help

Update Records in Salesforce

Table of ContentsUp

 Overview

The salesforce.sales.update() task is used to update a record in any of the supported modules in your Salesforce account, directly from your Zoho Creator application. For example, you can update Leads for sales, update Contacts of prospective sales, update Accounts or Campaigns for these sales etc.  To connect Zoho Creator with Salesforce, add a new connection from the Setup - Connections page. 

 Supported Modules

  • Lead
  • Contact
  • Account
  • Case
  • Solution
  • Product
  • Campaign

 Syntax

<salesforceResponse> = salesforce.sales.update(<salesforceConnectionName>, <salesforceModuleName>, <salesforceRecordID>, <params>);

where, 
<salesforceResponse> is the map variable returned as response. It contains the details of the updates to be made to the record. 
<salesforceConnectionName> refers to the connection name used to connect Zoho Creator with Salesforce. Create a new connection from the Setup - Connections page.
<salesforceModuleName> refers to the module name in Salesforce where the record needs to be updated.
<salesforceRecordID> refers to the ID of the record in Salesforce which needs to be updated.
<params> is the map variable that holds the key,value pairs. The map key is the label name in the format as specified in Salesforce. The map value is the field value as submitted from a Zoho Creator application.

 Example

A sample script to update a record in the Salesforce accounts module is given below. You can execute this script from a Zoho Creator form by adding it to the required Form Actions block.  For example, to edit a record in the accounts module, based on the given record ID,

  1. Select the Form from your Dashboard page.
  2. Go to the required Form Actions block.
  3. Add the script to the editor area.
  4. Click on Save Script to save the script definition.

    //get ID of the record to be updated
    getResponse = salesforce.sales.getRecords("Zoho","SELECT Name,Id FROM Account WHERE Name='John'");
    recordListObj = getResponse.get("records");
    if (recordListObj != null)
    {
    recordList = recordListObj.toJSONList();
    id = "";
    for each recordObj in recordList
    {
    recmap = recordObj.toMap();
    id = recmap.get("Id");
    }
    if (id != "")
    {

    //Declare Map Variable to hold the account details
    Details = map();

    //Add the account details to the map variable
    Details.put("AnnualRevenue",1000);
    Details.put("Industry","Chemicals");

    //updating the account in the Salesforce accounts module with record ID - "id"
    SalesforceResponse = salesforce.sales.update("Zoho", "Account", "id", Details);
    }
    }

Note

  • You can add the script directly to the editor area by selecting Free-flow scripting link displayed on the top-right corner of the script builder ( or ) use the drag-and-drop functionality in Script Builder.
  • In the above example, we have specified the param values directly within quotes. To fetch the param values from a Zoho Creator form, specify the field name used in the form. For example, if Annual_Revenue is the Field Deluge name, the key value pair should be specified in the following format: ("AnnualRevenue",  Annual_Revenue)

Response Format

The response returned by Salesforce will be in the format given below:

{"done":true}

If the execution fails due to incorrect parameter value,the response will be in the following format:

{
"message":"Cannot deserialize instance of currency from VALUE_STRING value thousand at [line:1, column:2]",
"errorCode":"JSON_PARSER_ERROR"
}

 Using Script Builder

To add the script using the drag-n-drop functionality in Script Builder,

  1. Select the Form from your Dashboard page.
  2. Go to the required Form Actions block.
  3. Click on Scrip Builder from the top-right corner of the page.
  4. Drag and drop the call function in the editor box. 
  5. Select Integration tasks
  6. Select Service as Salesforce
  7. Select Function as Update Record.
  8. Select the Connection Name to connect with Salesforce. Click on +Create to create a new connection or create a new connection from the Setup - Connections page.
  9. Select the required Module name in Salesforce.
  10. Insert the record ID of the record that needs to be updated in Salesforce.
  11. Select the map variable that holds the key-value pairs for the update request (or) click on "New Map" to add key-value pairs for the update request. 
  12. Specify the response variable that will hold the response returned by Salesforce.
  13. Click on Done to insert the call function task.


Upon submission of the form, the specific record gets updated in Salesforce with the given values. The response variable will contain the response returned by Salesforce. 

Share this post : FacebookTwitter

Still can't find what you're looking for?

Write to us: support@zohocreator.com