COQL or deluge API, how to get the total count that match criteria?

COQL or deluge API, how to get the total count that match criteria?

This is a simple count, but given the 200 record limit, and the fact that I don't need any of the results, just the count, why do I have to page through and perform such an expensive operation. The following shows how I successfully used deluge and COQL to aggregate a count, but again, there must be an easier way that is less expensive.  The following I use to count Contacts, and it iterates 32 times, that's 32 queries, just to get a single number: row count.

  1. selectQuery = "select id from Contacts WHERE id is not null";
    /**
    * @param {String} selectQuery - The select query to be executed
    * e.g. select id from module where id is not null
    * NOTE: the select query will have limit appended to it.  You must select the id.
    */
    queryMap = Map();
    attempt = " ";
    retryLoop = attempt.leftPad(99).replaceAll(" ",","); // Creates 100 loops
    iteration = 0;
    aggregateIds = List();
    for each retry in retryLoop
    {
      info "iteration: " + iteration;
      queryMap.put("select_query", selectQuery + " limit " + iteration*200 + ", 200");
      response = invokeurl
      [
        url :"https://www.zohoapis.com/crm/v3/coql"
        type :POST
        parameters:queryMap.toString()
        connection: "coql"
      ];
      //  Create a combined List
      for each pointer in response.get("data")
      {
          aggregateIds.add(pointer.get("id"));
      }
      if(response.get("info").get("more_records") == false)
      {
        break;
      }
      iteration = iteration + 1;
    }

    aggregateIdsSize = aggregateIds.size();
    info "aggregateIds: " + aggregateIdsSize + " for " + selectQuery;
    return aggregateIdsSize;
How can this be done more simply, with less computation and complication?

    Access your files securely from anywhere

        Zoho Developer Community




                                  Zoho Desk Resources

                                  • Desk Community Learning Series


                                  • Digest


                                  • Functions


                                  • Meetups


                                  • Kbase


                                  • Resources


                                  • Glossary


                                  • Desk Marketplace


                                  • MVP Corner


                                  • Word of the Day



                                      Zoho Marketing Automation


                                              Manage your brands on social media



                                                    Zoho TeamInbox Resources

                                                      Zoho DataPrep Resources



                                                        Zoho CRM Plus Resources

                                                          Zoho Books Resources


                                                            Zoho Subscriptions Resources

                                                              Zoho Projects Resources


                                                                Zoho Sprints Resources


                                                                  Qntrl Resources


                                                                    Zoho Creator Resources



                                                                        Zoho Campaigns Resources


                                                                          Zoho CRM Resources

                                                                          • CRM Community Learning Series

                                                                            CRM Community Learning Series


                                                                          • Kaizen

                                                                            Kaizen

                                                                          • Functions

                                                                            Functions

                                                                          • Meetups

                                                                            Meetups

                                                                          • Kbase

                                                                            Kbase

                                                                          • Resources

                                                                            Resources

                                                                          • Digest

                                                                            Digest

                                                                          • CRM Marketplace

                                                                            CRM Marketplace

                                                                          • MVP Corner

                                                                            MVP Corner





                                                                              Design. Discuss. Deliver.

                                                                              Create visually engaging stories with Zoho Show.

                                                                              Get Started Now