Get Records by ID from Salesforce

Table of Contents

 Overview

The salesforce.sales.getRecordById() task is used to get records from any of the supported modules in your Salesforce account, by specifying the unique ID of the record.  For example, you can get a Leads record from the Leads module in Salesforce with the given record ID.  To connect Zoho Creator with Salesforce, create a new connection from the Setup - Connections page. 

 Supported Modules

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

 Syntax

<salesforceResponse> = salesforce.sales.getRecordById(<salesforceConnectionName>, <salesforceModuleName>, <recordID>);

where, 
<salesforceResponse> is the map variable returned by Salesforce as response. It contains the details of the fetched record.
<salesforceConnectionName> referes 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 from where the record is fetched.
<recordID> is the ID of the record in Salesforce that needs to be fetched.

 Example

A sample script to get a record from the Salesforce Accounts module with a given record ID 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 fetch a record from the accounts module, based on the recordID,

    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.

      salesforceResonse = salesforce.sales.getRecordById("Zoho", "Account", "00190000010bRIMAA2");
      //returns a list of records with recordID = "00190000010bRIMAA2"

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.

 Response Format

The response returned by Quickbooks will be in the format given below.

{ "UpsellOpportunity__c":null,
"ParentId":null,
"Phone":null,
"TickerSymbol":null,
"SLAExpirationDate__c":null,
"Type":null,
"OwnerId":"00590000002l9KTAAY",
"LastModifiedDate":"2014-08-06T09:58:31.000+0000",
"ShippingState":null,
"AnnualRevenue":1000,
"BillingState":null,
"NumberofLocations__c":null,
"LastActivityDate":null,
"NumberOfEmployees":null,
"BillingPostalCode":null,
"SLASerialNumber__c":null,
"SystemModstamp":"2014-08-06T09:58:31.000+0000",
"ShippingCity":null,
"Description":null,
"BillingCountry":null,
"Site":null,
"ShippingCountry":null,
"LastModifiedById":"00590000002l9KTAAY",
"Website":null,
"ShippingStreet":null,
"AccountNumber":null,
"Fax":null,
"BillingStreet":null,
"SLA__c":null,
"Active__c":null,
"CustomerPriority__c":null,
"MasterRecordId":null,
"Name":"feb",
"BillingCity":null,
"Rating":null,
"CreatedById":"00590000002l9KTAAY",
"CreatedDate":"2014-08-06T09:58:31.000+0000",
"IsDeleted":false,
"Id":"00190000010xPIuAAM",
"Ownership":null,
"attributes":"{" type":"Account",
"url":"/services/data/v20.0/sobjects/Account/00190000010xPIuAAM"
}","ShippingPostalCode":null,
"Sic":null,
"Industry":"Chemicals"
}

If the execution fails due to Malformed Query, the response will be in the following format:

{
"message":"\nSELECT * FROM Account where Name='John'\n ^\nERROR at Row:1:Column:7\nunexpected token: '*'",
"errorCode":"MALFORMED_QUERY"
}

 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 Script 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 Get Record by ID.
      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 module name in Salesforce.
      10. Insert the record ID of the record that needs to be fetched.
      11. Specify the response variable that will hold the response returned by Salesforce.
      12. Click on Done to insert the call function task.


Upon submission of the form, the specific record gets fetched from Salesforce based on the given recordID. The response variable will contain the response returned by Salesforce.