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.
- week = zoho.currenttime.getWeekOfYear("Monday").toString(); // Get the current week of the year
- info week;
- clients = zoho.crm.getRecords("Accounts"); // Fetch all account records
- serviceAList = list(); // Initialize an empty list for 'Service A' records
- serviceBList = list(); // Initialize an empty list for 'Service B' records
- batchSize = 100; // Define the size of each batch
- totalProcessed = 0; // Track the total number of processed records
- for each client in clients
- {
- if(client.get("Status").contains("Active"))
- {
- // Check if the client has 'Service A'
- if(client.get("Services").contains("Service A"))
- {
- serviceAData = map(); // Create a map for storing 'Service A' data
- serviceAData.put("Week", week);
- serviceAData.put("Client", client.get("id"));
- serviceAData.put("Zone", client.get("Zone"));
- serviceAData.put("Neighborhood", client.get("Neighborhood"));
- serviceAData.put("Mobile", client.get("Mobile"));
- serviceAData.put("Service", ["Service A"]); // Store the service as a JSON array
- serviceAData.put("Last_Service", client.get("Last_Service"));
- serviceAList.add(serviceAData);
- }
- // Check if the client has 'Service B'
- if(client.get("Services").contains("Service B"))
- {
- serviceBData = map(); // Create a map for storing 'Service B' data
- serviceBData.put("Week", week);
- serviceBData.put("Client", client.get("id"));
- serviceBData.put("Zone", client.get("Zone"));
- serviceBData.put("Neighborhood", client.get("Neighborhood"));
- serviceBData.put("Mobile", client.get("Mobile"));
- serviceBData.put("Service", ["Service B"]); // Store the service as a JSON array
- serviceBData.put("Last_Service", client.get("Last_Service"));
- serviceBList.add(serviceBData);
- }
- }
-
- // Process batches of 100 records for 'Service A'
- if(serviceAList.size() >= batchSize)
- {
- responseServiceA = zoho.crm.bulkCreate("Tasks", serviceAList);
- info "Service A bulk creation - Batch " + ((totalProcessed / batchSize) + 1).toString();
- info responseServiceA;
- totalProcessed = totalProcessed + serviceAList.size();
- serviceAList.clear(); // Clear the list after processing
- }
- // Process batches of 100 records for 'Service B'
- if(serviceBList.size() >= batchSize)
- {
- responseServiceB = zoho.crm.bulkCreate("Tasks", serviceBList);
- info "Service B bulk creation - Batch " + ((totalProcessed / batchSize) + 1).toString();
- info responseServiceB;
- totalProcessed = totalProcessed + serviceBList.size();
- serviceBList.clear(); // Clear the list after processing
- }
- }
- // Process any remaining 'Service A' records
- if(!serviceAList.isEmpty())
- {
- responseServiceA = zoho.crm.bulkCreate("Tasks", serviceAList);
- info "Service A bulk creation - Final Batch";
- info responseServiceA;
- }
- // Process any remaining 'Service B' records
- if(!serviceBList.isEmpty())
- {
- responseServiceB = zoho.crm.bulkCreate("Tasks", serviceBList);
- info "Service B bulk creation - Final Batch";
- info responseServiceB;
- }
How the Code Works
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.
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.
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.
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.
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!
Access your files securely from anywhere
Zoho Developer Community
Deliver unforgettable customer experiences
Deliver unforgettable customer experiences
New to Zoho Marketing Plus?
Everything you need to run your marketing
New to Zoho Marketing Plus?
Everything you need to run your marketing
Zoho Desk Resources
-
Desk Community Learning Series
-
-
-
-
-
-
-
-
-
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 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
Zoho Show Resources
Writer Get Started. Write Away!
Writer is a powerful online word processor, designed for collaborative work.