Batch Processing of Records in Zoho CRM Using Deluge

Batch Processing of Records in Zoho CRM Using Deluge

Hello everyone,

I recently faced a challenge with bulk record creation in Zoho CRM, particularly when dealing with large numbers of records. Processing a significant volume of data all at once can lead to performance issues or even errors. To overcome this, I implemented a method that processes records in manageable batches, ensuring smooth and efficient execution.

Below is an example code that demonstrates how to handle records in Zoho CRM using batch processing. This code is designed to process "Service A" and "Service B" records for active clients, creating corresponding entries in a "Tasks" module in batches of 100 records. This approach prevents potential API limitations and ensures all records are processed effectively.

  1. week = zoho.currenttime.getWeekOfYear("Monday").toString();  // Get the current week of the year
  2. info week;

  3. clients = zoho.crm.getRecords("Accounts");  // Fetch all account records
  4. serviceAList = list();  // Initialize an empty list for 'Service A' records
  5. serviceBList = list();  // Initialize an empty list for 'Service B' records
  6. batchSize = 100;  // Define the size of each batch
  7. totalProcessed = 0;  // Track the total number of processed records

  8. for each client in clients
  9. {
  10.     if(client.get("Status").contains("Active"))
  11.     {
  12.         // Check if the client has 'Service A'
  13.         if(client.get("Services").contains("Service A"))
  14.         {
  15.             serviceAData = map();  // Create a map for storing 'Service A' data
  16.             serviceAData.put("Week", week);
  17.             serviceAData.put("Client", client.get("id"));
  18.             serviceAData.put("Zone", client.get("Zone"));
  19.             serviceAData.put("Neighborhood", client.get("Neighborhood"));
  20.             serviceAData.put("Mobile", client.get("Mobile"));
  21.             serviceAData.put("Service", ["Service A"]);  // Store the service as a JSON array
  22.             serviceAData.put("Last_Service", client.get("Last_Service"));
  23.             serviceAList.add(serviceAData);
  24.         }

  25.         // Check if the client has 'Service B'
  26.         if(client.get("Services").contains("Service B"))
  27.         {
  28.             serviceBData = map();  // Create a map for storing 'Service B' data
  29.             serviceBData.put("Week", week);
  30.             serviceBData.put("Client", client.get("id"));
  31.             serviceBData.put("Zone", client.get("Zone"));
  32.             serviceBData.put("Neighborhood", client.get("Neighborhood"));
  33.             serviceBData.put("Mobile", client.get("Mobile"));
  34.             serviceBData.put("Service", ["Service B"]);  // Store the service as a JSON array
  35.             serviceBData.put("Last_Service", client.get("Last_Service"));
  36.             serviceBList.add(serviceBData);
  37.         }
  38.     }
  39.     
  40.     // Process batches of 100 records for 'Service A'
  41.     if(serviceAList.size() >= batchSize)
  42.     {
  43.         responseServiceA = zoho.crm.bulkCreate("Tasks", serviceAList);
  44.         info "Service A bulk creation - Batch " + ((totalProcessed / batchSize) + 1).toString();
  45.         info responseServiceA;
  46.         totalProcessed = totalProcessed + serviceAList.size();
  47.         serviceAList.clear();  // Clear the list after processing
  48.     }

  49.     // Process batches of 100 records for 'Service B'
  50.     if(serviceBList.size() >= batchSize)
  51.     {
  52.         responseServiceB = zoho.crm.bulkCreate("Tasks", serviceBList);
  53.         info "Service B bulk creation - Batch " + ((totalProcessed / batchSize) + 1).toString();
  54.         info responseServiceB;
  55.         totalProcessed = totalProcessed + serviceBList.size();
  56.         serviceBList.clear();  // Clear the list after processing
  57.     }
  58. }

  59. // Process any remaining 'Service A' records
  60. if(!serviceAList.isEmpty())
  61. {
  62.     responseServiceA = zoho.crm.bulkCreate("Tasks", serviceAList);
  63.     info "Service A bulk creation - Final Batch";
  64.     info responseServiceA;
  65. }

  66. // Process any remaining 'Service B' records
  67. if(!serviceBList.isEmpty())
  68. {
  69.     responseServiceB = zoho.crm.bulkCreate("Tasks", serviceBList);
  70.     info "Service B bulk creation - Final Batch";
  71.     info responseServiceB;
  72. }

How the Code Works

  1. Initialization:

    • The script starts by retrieving the current week and all client records from the "Accounts" module. It also initializes empty lists for "Service A" and "Service B" records.
  2. Filtering and Data Preparation:

    • For each client, the script checks if the client is active and then further checks for the specific services ("Service A" or "Service B"). If a service is found, relevant data is stored in a map and added to the appropriate list.
  3. Batch Processing:

    • The code processes each list in batches of 100 records. Whenever a list reaches 100 records, the bulkCreate operation is triggered for the "Tasks" module, and the processed records are cleared from the list.
  4. Final Processing:

    • After iterating through all clients, any remaining records in the lists (those that didn't complete a batch) are processed in a final batch.
  5. Logging:

    • Throughout the process, informative messages are logged to track the batch processing, which helps in monitoring the script's execution.

Why This Approach?

  • Performance Efficiency: By processing records in batches, the script avoids hitting API limits or causing performance degradation in Zoho CRM.
  • Data Integrity: Ensures that no records are missed or duplicated during the bulk creation process.
  • Scalability: This method is scalable and can handle both small and large datasets efficiently.

This approach has worked well for me, and I hope it helps others facing similar challenges. Feel free to ask any questions or share your experiences with similar tasks!

    Zoho Desk Resources

    • Desk Community Learning Series


    • Digest


    • Functions


    • Meetups


    • Kbase


    • Resources


    • Glossary


    • Desk Marketplace


    • MVP Corner


    • Word of the Day


      • Sticky Posts

      • Zoho CRM Functions 53: Automatically name your Deals during lead conversion.

        Welcome back everyone! Last week's function was about automatically updating the recent Event date in the Accounts module. This week, it's going to be about automatically giving a custom Deal name whenever a lead is converted. Business scenario Deals are the most important records in CRM. After successful prospecting, the sales cycle is followed by deal creation, follow-up, and its subsequent closure. Being a critical function of your sales cycle, it's good to follow certain best practices. One such
      • Custom Function : Automatically send the Quote to the related contact

        Scenario: Automatically send the Quote to the related contact.  We create Quotes for customers regularly and when we want to send the quote to the customer, we have to send it manually. We can automate this, using Custom Functions. Based on a criteria, you can trigger a workflow rule and the custom function associated to the rule and automatically send the quote to customer through an email. Please note that the quote will be sent as an inline email content and not as a PDF attachment. Please follow
      • Function #50: Schedule Calls to records

        Welcome back everyone! Last week's function was about changing ownership of multiple records concurrently. This week, it's going to be about scheduling calls for records in various modules. Business scenario Calls are an integral part of most sales routines.. Sales, Management, Support, all the branches of the business structure would work in cohesion only through calls. You could say they are akin to engine oil, which is required by the engine to make all of it's components function perfectly. CRM
      • Function #37: Create a Purchase Order from a Quote

        Welcome back everyone! Last week, we learnt how to calculate the total number of activities for a lead and further take note of the activity count for particular dates. For instance, from the period of Demo to Negotiation. This week, let's look at a function that lets you create a Purchase Order instantly from a Quote. Business scenario: In any form of business, one of the most important things to do is to document the transactions. Naturally, negotiation, signing an agreement, placing an order,
      • Function-2: Round-Robin assignment of records

        Welcome back folks! Last week, we saw how to update sales commission in quotes using a custom function. This week, let's see an interesting use case asked by many of you - auto-assignment records by round-robin method. Business scenario: Right now, the solution allows you to auto-assign leads from web form and imported lists. Let us look at a need where you want to auto-assign leads from in-bound calls in a round-robin method, across modules. Prerequisite: You must create a permanent record in the

      Zoho CRM Plus Resources

        Zoho Books Resources


          Zoho Subscriptions Resources

            Zoho Projects Resources


              Zoho Sprints Resources


                Zoho Orchestly Resources


                  Zoho Creator Resources


                    Zoho WorkDrive Resources



                      Zoho Campaigns Resources

                        Zoho CRM Resources

                        • CRM Community Learning Series

                          CRM Community Learning Series


                        • Tips

                          Tips

                        • Functions

                          Functions

                        • Meetups

                          Meetups

                        • Kbase

                          Kbase

                        • Resources

                          Resources

                        • Digest

                          Digest

                        • CRM Marketplace

                          CRM Marketplace

                        • MVP Corner

                          MVP Corner




                          Zoho Writer Writer

                          Get Started. Write Away!

                          Writer is a powerful online word processor, designed for collaborative work.

                            Zoho CRM コンテンツ




                              ご検討中の方