Creator Help

Search Records in Salesforce

Table of Contents

 Overview

The salesforce.sales.searchRecords() task is used to search records in any of the supported modules of your Salesforce account, directly from your Zoho Creator Application. For example, you can search records with specific Lead Name, Contact Name or Accounts Name from Salesforce modules like Leads, Contacts, Accounts 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.searchRecords(<salesforceConnectionName>, <selectQuery>);

where, 
<salesforceResponse> is the map variable returned as response. It contains the details of the record that needs to be fetched. 
<salesforceConnectionName> refers to the connection name used to connect Zoho Creator with Salesforce. Create a new connection from the Setup - Connections page.
<selectQuery> contains the details of the record that you want to search. It must be in the following format:
select <requiredColumns> from <moduleName> where <attribute name> = <value>. For example, ("SELECT Name,Id FROM Account WHERE Industry='Chemicals'")

 Example

A sample script to search a record from 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 search a record from the accounts module, based on the query,

  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.

    //search record with value of (industry = chemicals) from the Salesforce accounts module
    SalesforceResponse = salesforce.sales.searchRecords("Zoho","SELECT Name,Id FROM Account WHERE Industry='Chemicals'");

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 Salesforce will be in the format given below:

{"done":true,"records":"[{"Name":"John","Id":"00190000010xPIuAAM","attributes {"type":"Account","url":"/services/data/v20.0/sobjects/Account/00190000010xPIuAAM"}}]"

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 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 Search Records.
  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. Insert the query to fetch record.
  10. Specify the response variable that will hold the response returned by Salesforce.
  11. 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 query. 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