Mass Delete Records Across Modules

Mass Delete Records Across Modules

Season's greetings to our coding enthusiasts! 

Let us code our way into the festive spirit with another insightful post in our Kaizen series!

In this post, we will explore the process of creating a custom button using functions on the records' detail page. This enables the deletion of all associated child records when the current record is deleted. To fulfill this requirement, we will leverage APIs like COQL API, Records API, and Mass Delete API.

Currently, Zoho CRM provides the delete action exclusively for a specific related list modules when the parent record is deleted. Here are the specifics of ZOHO CRM's default support for deleting related list modules:

Record Module
Related List Module
Leads
Activities, Visits and Email Drafts
ContactsActivities, Visits, Appointments and Email Drafts
Accounts
Activities, Contacts, Deals, Quotes, Sales Orders, Invoices, Cases, Appointments and Email Drafts
Deals
Activities, Cases, Competitors and Email Drafts
Campaigns
Activities, Email Drafts and Child Campaigns 
Cases
Activities and Email Drafts
Products
Activities, Solutions, Cases and Email Drafts
Vendors
Activities and Email Drafts
Quotes
Activities and Email Drafts
Sales Orders
Activities and Email Drafts
Purchase Orders
Activities and Email Drafts
Invoices
Activities and Email Drafts
Services
Appointments and Email Drafts
Custom
Activities and Email Drafts

Perform Mass Delete Across Modules

Assume that you are the Manager of Zylker, an educational institution utilizing ZOHO CRM for customer relationship management. You have implemented custom modules, namely Training Program and Participants in your organization. 

Now, you aim to streamline record management by creating a custom button on the Training Program module's records detail page. On triggering, this button should delete all associated participants of a specific program along with the program itself. 

Let us guide you through the step-by-step process of fulfilling this requirement using ZOHO CRM functions.

Prerequisites

Achieving this requirement is versatile, applicable to both records with a single child module as well as records with multiple child modules. 

A lookup field serves to establish a connection between two modules, designating the module where the lookup field is employed as the child module. The module that the lookup field points to is referred to as the parent module.

To keep it simple, let us consider Participants as the child module with a lookup relationship to the Training Program parent module. 

The knowledge of COQL, Records and Mass Delete Records APIs, Deluge Script and ZOHO CRM Functions ensure effective execution of our outlined process.

Creating a Custom Button

Step 1: Begin by navigating to Setup > Customization > Modules and Fields > Training Program > Links and Buttons > New Button within your ZOHO CRM interface.

Step 2: Provide a name and description for the button. Next, select the Details Page as the designated location for the button from the drop-down menu.



Refer to this document to learn more on creating and using custom buttons.

Step 3: Configure the button's action by selecting Writing Function from the menu.



Step 4: Fill in the basic details for creating a new function. 

Step 5: After clicking the create button, you will be directed to an editor interface, as depicted in this image.



You have to code your function logic in this editor and click the Save button on the top right corner. 

For the scenario discussed, we have attached the function code in a zip file with this post. Download and explore the code to gain hands-on experience in this use case. 

Step 6: Next, you will be redirected to the Links and Buttons page, where you need to configure the visibility of the button based on profiles. Afterward, click on the Save button to confirm your settings.


Flow of the function

The function should initially make a COQL API call to retrieve the participant records that correspond to the record ID of the training program from which the button is triggered. This API can fetch up to 2000 related child records in a single API call.

queryMap = Map();
queryMap.put("select_query","select id from Participants where Training_Program =" + id + "Limit 2000");
response = invokeurl
[
type :POST
parameters:queryMap.toString()
connection:"crm_oauth_connection"
];

Here, connections are used to make ZOHO CRM API calls. To get the current record ID, you have to configure it in function arguments. 

Click Edit Arguments from the top of the page and associate the Training Program ID as shown in this image. 



Before proceeding to the next step, it's crucial to be aware of the following constraints associated with the APIs:
  • COQL API: It can retrieve a maximum of 2000 records per API call.
  • Delete Records API: It has the capability to delete up to 100 records in a single API call.
  • Mass Delete Records API: By utilizing record IDs, it can delete a maximum of 500 records per API call.
Given these constraints, the following logic has been devised to address our specified requirement:

--->  If the participant count is 0, the system should proceed to delete the current record exclusively. 
--->  Incases where the record count is below 100, the Delete Record API must be employed to eliminate records from the Participants module.
--->  If the participant count exceeds 100, the Mass Delete Records API should be used for deleting records within the child module. For scenarios where more than 500 records need deletion, it is necessary to execute this in a loop for four iterations with each deleting 500 records.

Let us execute this logic in Deluge script,

if(!isNull(response))
{
response = response.toMap();
count = response.getJSON("info").get("count").toNumber();
has_more = response.getJSON("info").get("more_records");
id_list = List();
itr_list = {0,1,2,3};
response = response.getJSON("data");
result = List();
if(count > 0)
{
for each  item in response
{
id_list.add(item.getJSON("id"));
}
if(count > 100)
{
end = 0;
start = 0;
for each  itr in itr_list
{
if(count / 500 - itr > 0)
{
idMap = Map();
if(count - end > 500)
{
end = end + 500;
}
else
{
end = count;
}
idMap.put("ids",id_list.subList(start,end));
response = invokeurl
[
type :POST
parameters:idMap.toString()
connection:"crm_oauth_connection"
];
start = end;
}
}
}
else
{
response = invokeurl
[
type :DELETE
connection:"crm_oauth_connection"
];
}
}
}

Now, let us address the scenario of a training program with over 2000 participants. Following the logic outlined above, our custom button will handle the deletion of only 2000 records. 

To manage this, after successfully deleting the initial 2000 records, the record from the Training Program module should not be deleted. Here, we have to configure a pop-up message signaling that additional records require deletion. To proceed, users must click the same button to eliminate the remaining records along with the current one.

After deleting all records from the child modules, the custom button will proceed to remove the current Training Program record, as shown in the following Deluge code.

if(isNull(response) || !has_more)
{
response = invokeurl
[
type :DELETE
connection:"crm_oauth_connection"
];
return "Deleted Successfully";
}
return "Over 2000 related records were detected. Click 'Cascade Delete' again to delete the remaining and this training program. ";

Let us now check our custom button from the details page of the Training Programs module. 



To prevent additional clicks for deleting the remaining records, we will circle back to you on next Friday with a solution that incorporates the looping mechanism. 
 
We have also brought you a wave of innovation and enhanced features in our V6 APIs. Take a look at them and empower your coding journey with us. 

If you have any queries, feel free to drop them in the comments section below or reach out to us directly at support@zohocrm.com. We eagerly await your thoughts and feedback on this!

Cheers to a productive and joyful season!


    Access your files securely from anywhere







                            Zoho Developer Community





                                                  Use cases

                                                  Make the most of Zoho Desk with the use cases.

                                                   
                                                    

                                                  eBooks

                                                  Download free eBooks and access a range of topics to get deeper insight on successfully using Zoho Desk.

                                                   
                                                    

                                                  Videos

                                                  Watch comprehensive videos on features and other important topics that will help you master Zoho Desk.

                                                   
                                                    

                                                  Webinar

                                                  Sign up for our webinars and learn the Zoho Desk basics, from customization to automation and more

                                                   
                                                    
                                                  • Desk Community Learning Series


                                                  • Meetups


                                                  • Ask the Experts


                                                  • Kbase


                                                  • Resources


                                                  • Glossary


                                                  • Desk Marketplace


                                                  • MVP Corner




                                                            • Sticky Posts

                                                            • Kaizen #197: Frequently Asked Questions on GraphQL APIs

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Kaizen #198: Using Client Script for Custom Validation in Blueprint

                                                              Nearing 200th Kaizen Post – 1 More to the Big Two-Oh-Oh! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Celebrating 200 posts of Kaizen! Share your ideas for the milestone post

                                                              Hello Developers, We launched the Kaizen series in 2019 to share helpful content to support your Zoho CRM development journey. Staying true to its spirit—Kaizen Series: Continuous Improvement for Developer Experience—we've shared everything from FAQs
                                                            • Kaizen #193: Creating different fields in Zoho CRM through API

                                                              🎊 Nearing 200th Kaizen Post – We want to hear from you! Do you have any questions, suggestions, or topics you would like us to cover in future posts? Your insights and suggestions help us shape future content and make this series better for everyone.
                                                            • Client Script | Update - Introducing Commands in Client Script!

                                                              Have you ever wished you could trigger Client Script from contexts other than just the supported pages and events? Have you ever wanted to leverage the advantage of Client Script at your finger tip? Discover the power of Client Script - Commands! Commands


                                                            Manage your brands on social media



                                                                  Zoho TeamInbox Resources



                                                                      Zoho CRM Plus Resources

                                                                        Zoho Books Resources


                                                                          Zoho Subscriptions Resources

                                                                            Zoho Projects Resources


                                                                              Zoho Sprints Resources


                                                                                Qntrl Resources


                                                                                  Zoho Creator 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


                                                                                            Zoho Show Resources


                                                                                              Zoho Writer Writer

                                                                                              Get Started. Write Away!

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

                                                                                                Zoho CRM コンテンツ








                                                                                                  Nederlandse Hulpbronnen


                                                                                                      ご検討中の方




                                                                                                            • Recent Topics

                                                                                                            • Issue on Upload API and href image URL

                                                                                                              Here is my Full API Code , URL : URL: https://desk.zoho.com/api/v1/uploads/659563000000193003/content Headers* Authorization: 'Zoho-oauthtoken 1000.ed5ce2836bf5ba9b946f5ec9************88e73ff4883a3e9c58ffeb7870' orgId: 7586***** RESPONSE{ "errorCode":
                                                                                                            • Issue when downloading a Mail Merged Zoho Writer Document as .docx

                                                                                                              Hi, We are using within Zoho CRM mailmerge to create documents. This results in a Zoho Writer document. When we try to download as a Microsoft Docx file we get following error: "Word experienced an error trying to open the file. Try these suggestions.
                                                                                                            • 【Zoho CRM】ケイデンス機能のアップデート

                                                                                                              ユーザーの皆さま、こんにちは。コミュニティチームの中野です。 今回は「Zoho CRM アップデート情報」の中から、ケイデンス機能のアップデートをご紹介します。 ケイデンス機能の2つの強化されたことで、適用と解除のタイミングをより柔軟に管理できるようになり、 よりタイムリーで的確なコミュニケーションが実現できるようになりました。 目次: 1. ケイデンスの再開/最初からのやり直し 2. ケイデンスからのデータ解除タイミングの設定 1. ケイデンスの再開/最初からのやり直し 手動削除、完了、または適用解除条件が満たされた場合など、以前に適用解除されたデータをケイデンスに再適用できるようになりました。
                                                                                                            • Rescheduled US meetups: Zoho Desk user meetups are coming to seven U.S. cities in October and November, 2025

                                                                                                              Hello to our Zoho Desk users in the United States, We're excited to share the revised dates for the upcoming Zoho User Groups happening across the US this summer. Our product experts are heading to seven cities throughout the country, and for the first
                                                                                                            • Anyone get the OpenAI API to work in Zoho Meeting?

                                                                                                              Has anyone been able to get the OpenAI API to work in generating meeting summaries? I have been trying, but I get an error that says "OpenAI key notes request rate exceeded. Please try again later or upgrade your open AI account." I contacted Zoho support
                                                                                                            • Push Notifications Customization

                                                                                                              There is no way to customize the notifications we get. I would like to be able to get notifications based on if they are assigned directly to me, my team, my department, or perhaps tickets that match a specific criteria (a contact or account is a VIP
                                                                                                            • Announcing Early Access to the next generation of Zoho Desk UI

                                                                                                              Customer service is one of the categories where efficiency and quality of service have to run in parallel, and your team's experience with their helpdesk goes a long way ensuring these aspects are uncompromised. Introducing DOT Design for Zoho Desk -
                                                                                                            • Editing the record in report

                                                                                                              I have a use-case as below- User creates a assessment record by filling some fields. User assigns that record to portal user by using Assigned To dropdown (Assigned To is Users field in form with choices as customers). I have set the record owner of form
                                                                                                            • Unified WhatsApp Number Management in Zoho Desk and SalesIQ

                                                                                                              Dear Zoho Desk Support Team, We are currently utilizing both Zoho Desk and Zoho SalesIQ for our customer support operations. While both platforms offer WhatsApp integration, we are facing challenges due to the requirement of separate WhatsApp numbers
                                                                                                            • Can we have Bills of Material Module ?

                                                                                                              Can we have Bills of Material Module ?
                                                                                                            • Main Ticket Page Customization

                                                                                                              We do not love the ticket list page (right after clicking Tickets menu item) would like options to customize it.
                                                                                                            • Communicating with emojis

                                                                                                              On July 17, we celebrate World Emoji Day! We're a bit late 😐 sharing insights about this day. But we just couldn't let it pass without a mention 😊 because emojis have a meaningful connection with customer service 💬 🤝. We do not want to miss out on
                                                                                                            • Agent Collision Missing from Mobile App

                                                                                                              Please add Agent Collision capabilities to the mobile app.
                                                                                                            • Zia Sentiment and Functionality on Mobile

                                                                                                              Please add Zia sentiment and generative responses to the mobile app. It would be nice to see the ticket sentiment and generate a response back to a user using Zia on my iPhone
                                                                                                            • View Account Attachments on iOS

                                                                                                              Please allow us to view account attachments on the mobile iOS app!
                                                                                                            • How do I run a PnL by Sales Person?

                                                                                                              I am trying to run a PnL by sales person but am not seeing the option do so. All I need to know (per salesperson) is revenue, cost of goods, gross profit.
                                                                                                            • View Contracts and Support Plans on Mobile

                                                                                                              We would like to be able to see contracts and support plans from the mobile app on iOS!
                                                                                                            • Why is Zoho Meeting quality so poor?

                                                                                                              I've just moved from Office 365 to Zoho Workplace and have been generally really positive about the new platform -- nicely integrated, nice GUI, good and easy-to-understand control and customisation, and at a reasonable price. However, what is going on
                                                                                                            • App like Miro

                                                                                                              Hi all, is there a way to have a interactive whiteboard like in Miro? We want to visualize our processes and workflows in an easy way.
                                                                                                            • Loan repayment Entry

                                                                                                              While receiving loan, i does following steps in My Zoho books. 1. Create "Loan & Advance " Account as Parent Account under Long Term Liabilities. 2. Create another account For Example "Mr. ABC's Loan as Child account under the parent account. Now: In
                                                                                                            • Quotes module send email reverted back into 2022??

                                                                                                              Our Zoho CRM PLUS quotes, sales orders, invoice modules is showing us an email composer from 2022. We cannot send emails and its been a real pain. I tried clicking the new version over there but it doesnt seem to do anything. Any help is welcome. th
                                                                                                            • Workflow Condition - how do check that a date / time value is in the past?

                                                                                                              Hello, I'm got a workflow that runs a function when records reach their 'Effective Date / Time', but sometimes records are created after the 'Effective Date / Time' so I have another workflow that checks for records which needs to be processed immediately.
                                                                                                            • Pre filling SignForm field values by URL field alias's in Zoho Sign

                                                                                                              Hi, Does anyone know if it's possible to pre fill the field values of the SignForm by using field alias's like you can in Zoho forms? To be more specific, I want to be able to change the SignForm URL to include some information like this: Before : https://sign.zoho.eu/signform?form_link=234b4d535f495623920c288fc8538cb9e6db03bbfd44499b63f3e5c48daf78f44bc47f333e2f5072cc1ee74b7332fe18b25c93fab10cb6243278d49c67eacbf30bbe5b6e1cc8c6b2#/
                                                                                                            • How to Split Payout in Zoho Books (Without Using Journal?)

                                                                                                              Hi, I'm trying to properly record payouts in Zoho Books. The issue is that each payout is a combination of sales and expenses (fees). When I try to categorise the payout transaction from the Banking tab, I can only split the transaction using income-type
                                                                                                            • Payment Schedule

                                                                                                              Please add the ability to create a payment schedule. The other options, like retainer invoices or two invoices, do not work for the customer.  We invoice a client and need to be able to show them everything they owe in one invoice, and when each payment
                                                                                                            • Google Recaptcha V3

                                                                                                              Hi, Why, years later now, are we still waiting for Zoho Forms to incorporate Google Recaptcha V3 into it's systems? Come on Zoho this has been an ongoing issue for over a year now!! It should be a priority.
                                                                                                            • Which pricing system do you think would work best for us?

                                                                                                              Imagine we’re selling strictly wholesale. We’d rather not publish unit prices; instead, we quote customers case-by-case. To spur larger orders, we’re considering a transparent discount ladder—say: $0 – $999: 0 % $1,000 – $1,999: 5 % $2,000 – $4,999: 10
                                                                                                            • Add Support for Google reCAPTCHA v3 in Zoho Forms

                                                                                                              Hello Zoho Forms Team, We appreciate the security measures currently available in Zoho Forms, including Zoho CAPTCHA, Google reCAPTCHA v2 (checkbox), and reCAPTCHA v2 (Invisible). However, we would like to request the addition of support for Google reCAPTCHA
                                                                                                            • Can't Remove Payment Gateway

                                                                                                              I am getting the error "Settings cannot be cleared as some of the transactions are still in progress." when trying to remove the PayGate payment gateway which I was unable to get working. I am now using paystack and I want to remove Paygate.
                                                                                                            • Sync specific Zoho Inventory Warehouses to Zoho Commerce

                                                                                                              As said in the title, we would want to only sync stock from one warehouse of Zoho Inventory to the Zoho Commerce item stock. We have a 2 warehouses in different countries and the way that Zoho Commerce works (It takes stock from ALL WAREHOUSES EVERYWHERE
                                                                                                            • Weekly Tips : Automatically clean clutter with Junk cleanup interval

                                                                                                              If you regularly receive many unwanted or spam emails, your Spam folder can quickly fill up and start taking up valuable storage space in your Zoho Mail account. Instead of manually clearing it every few days, you might find it helpful to enable automatic
                                                                                                            • Any solution for getting portal users list in deluge or in widget

                                                                                                              Hi Team, Has anyone able to find the solution to get portal users list in deluge or in zoho creator widgets? Thanks, Payal
                                                                                                            • The Grid is here!

                                                                                                              Hey Zoho Forms Community! 👋 We’re thrilled to announce the launch of a feature that’s been on your wishlist for a while: Grids What is Grids? Grids let you place form fields side by side in multiple columns to create a more concise and organized form
                                                                                                            • Steuerberater der Zoho benutzt in Deutschland

                                                                                                              I write in English because the issue is related to German regulations. Wir sind ein Unternehmen, welches aktuell keine Pflicht zur doppelten Buchführung hat. Aktuell bucht unser Steuerberater jeden Beleg, auch unsere Auslagen. Wir würden dies gerne selbst
                                                                                                            • GraphQL in new Send Webhooks feature

                                                                                                              Hello, is it possible to use GraphQL apis in the new Send Webhooks feature?
                                                                                                            • # 2 Why do we need a billing system when accounting covers billing?

                                                                                                              In today's evolving financial tech stack, businesses use a mix of tools to manage their day-to-day operations, from invoicing to full-fledged accounting. While accounting platforms typically come with built-in invoicing features, specialized billing systems
                                                                                                            • How to insert an Excel/Zoho Sheet table in a chat?

                                                                                                              Hello, is there a way to paste an excel/zoho sheet table to a conversation without loosing table lines. I tried to paste a piece of a table and all the columns and rows were gone. How to easily paste a table without a need of sending a file? Katarzy
                                                                                                            • Mass Update Application Status

                                                                                                              How to update application statuses of Multiple Applications at once? Is that possible? If not then why please consider adding it It can save hours of manual work Thats the only Option I see
                                                                                                            • Free webinar: Streamlining customer service paperwork with the Zoho Sign extension for Zoho Desk

                                                                                                              Hi there! Wondering how to bridge the gap between digitized customer service and business paperwork? Attend our free webinar to learn how you can do this by connecting Zoho Sign, our digital signature app, with Zoho Desk, our online customer service help
                                                                                                            • Mail Search Not Working

                                                                                                              Hello, Mail search is not working at all. I've tried Chrome and Mozilla. I can try and search for an exact term, or even an email that is 1st in my email list. All search does is sit and spin, or it comes up with no results. I've also tried it on my android
                                                                                                            • Next Page