For Zoho services only


I'm currently part of a wider delivery team at Ascent Business Solutions, recognised as a leading Zoho Premium Solutions Partner in the United Kingdom.

Ascent Business Solutions support organisations with everything from targeted technical fixes through to full Zoho CRM implementations and long-term platform adoption. Working as a team rather than a one-person consultancy allows projects to move forward consistently, with access to the right skills at each stage.

The team I manage specialises in API integrations between Zoho and third-party finance and commerce platforms such as Xero, Shopify, WooCommerce, and eBay. Much of our work involves solving integration challenges that fall outside standard documentation, supporting new ideas, new sectors, and evolving business models.

Success is measured through practical outcomes and return on investment, ranging from scaling small operations into high-turnover businesses to delivering rapid gains through online payments, automation, and streamlined digital workflows.

If you are looking for structured Zoho expertise backed by an established consultancy, you can contact Ascent Business Solutions on 0121 392 8140 (UK), email info@ascentbusiness.co.uk, or visit https://www.ascentbusiness.co.uk.
Zoho CRM: searchRecords with sorted results

Zoho CRM: searchRecords with sorted results

What?
This is an article to document how to use the searchRecords function in CRM and to sort the results response.

Why?
This is unclear and not always working as coded below since each system (CRM, Creator, Books) seems to interpret this sorting feature differently. This article is an effort to find clear and working solutions. It is working again as of 2022-02-10.

How?
Two methods listed here, the standard searchRecords() and then the getRecords() functions:

  1. Set the record ID to your own record ID.
  2. Set the list of pages to the number of pages you want to search. Keep in mind script execution limits set by Zoho.
  3. Set the search criteria string to your specific requirements (:equals:, :starts_with:, |=|). If 1 expression then you can omit the parenthesis. If multiple expressions then separate each with parenthesis joined by "and" or "or". Nulls are not returned.
  4. Set the "ModuleToSearch" to the API Name of the module you want to search.

Method #1: zoho.crm.searchRecords()
Contrary to the documentation saying there are only the approved and converted values supported in additional parameters, I find the below works in CRM just fine: As of 2025, this method no longer works. Please refer to method 2 using a search API or a COQL query (see below).
copyraw
// ****************** CODE USING SEARCHRECORDS ****************
//
// init
v_RecordID = 1234567890123456789;
//
// loop through 5 pages of 200 records = 1000 records
l_Pages = [1,2,3,4,5];
//
// set search criteria
v_SearchCriteria = "Lead:equals:" + v_RecordID + "";
//
// set results parameters
m_SearchParam = Map();
m_SearchParam.put("sort_by", "Modified_Time");
m_SearchParam.put("sort_order", "asc");
//
// loop through each page
for each  v_Page in l_Pages
{
	l_SearchResults = zoho.crm.searchRecords("ModuleToSearch", v_SearchCriteria, v_Page, 200, m_SearchParam);
	//
	// loop through search results
	for each r_Result in l_SearchResults
	{
		// check that there is an ID on this record to avoid looping through error messages
		if(!isNull(r_Result.get("id")))
		{
			// do stuff to each record...
			info r_Result.get("id");
		}
	}
	//
	// stop looping if less than 200 records on this page
	if(l_SearchResults.size() < 200)
	{
		break;
	}
}
  1.  // ****************** CODE USING SEARCHRECORDS **************** 
  2.  // 
  3.  // init 
  4.  v_RecordID = 1234567890123456789
  5.  // 
  6.  // loop through 5 pages of 200 records = 1000 records 
  7.  l_Pages = [1,2,3,4,5]
  8.  // 
  9.  // set search criteria 
  10.  v_SearchCriteria = "Lead:equals:" + v_RecordID + ""
  11.  // 
  12.  // set results parameters 
  13.  m_SearchParam = Map()
  14.  m_SearchParam.put("sort_by", "Modified_Time")
  15.  m_SearchParam.put("sort_order", "asc")
  16.  // 
  17.  // loop through each page 
  18.  for each  v_Page in l_Pages 
  19.  { 
  20.      l_SearchResults = zoho.crm.searchRecords("ModuleToSearch", v_SearchCriteria, v_Page, 200, m_SearchParam)
  21.      // 
  22.      // loop through search results 
  23.      for each r_Result in l_SearchResults 
  24.      { 
  25.          // check that there is an ID on this record to avoid looping through error messages 
  26.          if(!isNull(r_Result.get("id"))) 
  27.          { 
  28.              // do stuff to each record... 
  29.              info r_Result.get("id")
  30.          } 
  31.      } 
  32.      // 
  33.      // stop looping if less than 200 records on this page 
  34.      if(l_SearchResults.size() < 200) 
  35.      { 
  36.          break; 
  37.      } 
  38.  } 

Method #2: using COQL
copyraw
// ****************** CODE USING GETRECORDS ****************
// init
l_Pages = {1,2,3,4,5};
v_PerPage = 200;
//
// get other products with the same name (set in order of oldest first and keep only first one, delete the others)
m_Params = {"select_query":"select id, Product_Name from Products where Product_Name = '" + v_SearchName + "' order by id limit " + v_PerPage};
r_CoqlSortedProducts = invokeUrl 
[ 
	url :"https://www.zohoapis.eu/crm/v7/coql" 
	type :POST 
	parameters:m_Params.toString()
	connection:"zcrm" 
];
l_SortedProducts = ifnull(r_CoqlSortedProducts.get("data"), List());
  1.  // ****************** CODE USING GETRECORDS **************** 
  2.  // init 
  3.  l_Pages = {1,2,3,4,5}
  4.  v_PerPage = 200
  5.  // 
  6.  // get other products with the same name (set in order of oldest first and keep only first one, delete the others) 
  7.  m_Params = {"select_query":"select id, Product_Name from Products where Product_Name = '" + v_SearchName + "' order by id limit " + v_PerPage}
  8.  r_CoqlSortedProducts = invokeUrl 
  9.  [ 
  10.      url :"https://www.zohoapis.eu/crm/v7/coql" 
  11.      type :POST 
  12.      parameters:m_Params.toString() 
  13.      connection:"zcrm" 
  14.  ]
  15.  l_SortedProducts = ifnull(r_CoqlSortedProducts.get("data"), List())

Source(s):
Category: Zoho CRM :: Article: 339

Credit where Credit is Due:


Feel free to copy, redistribute and share this information. All that we ask is that you attribute credit and possibly even a link back to this website as it really helps in our search engine rankings.

Disclaimer: Please note that the information provided on this website is intended for informational purposes only and does not represent a warranty. The opinions expressed are those of the author only. We recommend testing any solutions in a development environment before implementing them in production. The articles are based on our good faith efforts and were current at the time of writing, reflecting our practical experience in a commercial setting.

Thank you for visiting and, as always, we hope this website was of some use to you!

Kind Regards,

Joel Lipman
www.joellipman.com