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




                                        • Desk Community Learning Series


                                        • Digest


                                        • Functions


                                        • Meetups


                                        • Kbase


                                        • Resources


                                        • Glossary


                                        • Desk Marketplace


                                        • MVP Corner


                                        • Word of the Day


                                        • Ask the Experts





                                                  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

                                                                                                  • Deluge Script to Reopen Ticket if Tasks are not Completed

                                                                                                    I have the following script, my goal is to have it automatically reopen the ticket when the ticket is closed if there are Activities assigned to the ticket that are not "Completed". This script seems to reopen the ticket if there are any tasks at all,
                                                                                                  • UK payroll entries

                                                                                                    Hey guys, Nett payroll payments are imported direct into the bank, using an external payroll system (will be glad for Zoho to have a UK payroll app) At present I have monthly recurring bills for HMRC which are auto entered & paid when due. This seems
                                                                                                  • What are the consequences of renaming a picklist value?

                                                                                                    What are the consequences of renaming a picklist value?
                                                                                                  • Integrating Zoho Creator with Google Drive

                                                                                                    I am interested in using Google Drive as a convenient repository to push files from file upload fields in my creator app. I am wondering if people have come up with best practices for this or even how viable it is. https://developers.google.com/drive/api/guides/manage-uploads#simple
                                                                                                  • Subform Lookup field showError doesn't clear in Client Script

                                                                                                    I have a lookup fields Deal, Account and Lead in Subform, I am checking if its null or not If its null It shows an error, but when I select some value for the Lookup Field it doesn't clear the error , for other fields such as single line or pickup etc.
                                                                                                  • Option to Manually Add and Verify DMARC Record

                                                                                                    Dear Zoho Mail Team, When configuring a new domain in Zoho Mail, we currently have the option to automatically configure the MX, SPF, and DKIM records. For each of these, we can either allow Zoho to create the records or manually add them to our DNS and
                                                                                                  • Zoho Desk & Tasks

                                                                                                    Hi, I'd like to be able to create a set of tasks each time a customer request comes in, as I understand it, currently each would need to be create manually. Project is too much of an overhead for what we want to use. Effectively in various use cases we
                                                                                                  • Working with Products that are non-tangible

                                                                                                    How does one create a 'service' in products? Is there a way to disable inventory functions for things like Sofware as a service? The services module doesn't look to be much help either. Not sure how to do this in CRM
                                                                                                  • Weekly Tips: Categorize Your Emails with Tags

                                                                                                    We send and receive hundreds of emails each week—ranging from work-related updates, personal messages, important documents, and even spam. With so many emails flooding your inbox, it can quickly become chaotic. Some emails are urgent, some are for reference,
                                                                                                  • Create vendor via API

                                                                                                    The Zoho Books web ui has an option to add a new vendor. Though I can't find an API to create a vendor. Is there an API available for creating a new vendor? Regards, Vinod
                                                                                                  • Function to check frequency of customer ordering patterns

                                                                                                    Hi, I'm no coder, so I thought I could make use of Chat GPT to generate some Deluge script to create a function that would check order frequency of our customers so that I could send an email if they go beyond their usual order pattern. Chat GPT and Claude
                                                                                                  • Customization of "List Price" naming convention

                                                                                                    Surely this has been brought up before, but does Zoho plan to allow the customization of the List Price field? For example, the ability to rename to: Sell Price Sale Price Market Price Ticket Price etc etc
                                                                                                  • Dashboard Analytics - Time to fill a job

                                                                                                    Hello! I'm creating a dashboard and want a chart that displays the recruitment SLA (time to fill) of job openings. I created a report that retrieves the SLA for each job opening. However, when generating the chart, the information does not appear as I
                                                                                                  • Zoho People U.S. Compensation Setup

                                                                                                    We're new to Zoho and Zoho People Plus. So far, we like what we see as an HRIS system to suit our small USA-based (under 20-person) non-profit. However, we can't figure out how to configure the Compensation Service to reflect our workplace. We'd simply
                                                                                                  • Zoho Desk - Archiving Contacts

                                                                                                    Hi, We have a lot of customers in Zoho Desk with associated contacts. When a contact leaves we want to be able to still have their tickets in our history as this is important. But we don't want to have all these contacts that no longer work for the company.
                                                                                                  • Zoho Desk integration with Power BI

                                                                                                    Hi, I want to be able to create a Power BI report which has live updates of ticket data from zoho desk, is this possile at all? Thanks Jack
                                                                                                  • 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
                                                                                                  • Zoho books not accepting valid state code via api

                                                                                                    Hello, I am using make.com to create a contact and then invoice for a Shopify orders. However, while creating contact I'm getting "please provide a valid state code" error even though I'm providing correct state code. For example I'm providing MH as state
                                                                                                  • Create View to See Tickets Closed within the last 3 days

                                                                                                    I'm trying to create a view in Zoho Desk that shows me "recently closed ticket," which I will define as tickets closed in the last 3 days. I want this view to update so that whenever I click to view it is recalculates and shows me tickets closed within 3 days from that moment. When I try to Create a view and use the criteria of "Ticket Closed Time" I have to specify a discrete time frame (on or before a specific date). It doesn't allow me to define time/date dynamically like I can do with date fields
                                                                                                  • I'm so confused by the new (?) look

                                                                                                    I've been off Notebook for a long time, neglecting the app and never visiting the website. I decided to renew my commitment to it. It looks completely different! When I logged on before (app or browser page) I'd see a very pretty display of my multiple
                                                                                                  • Conexão de Meta Ads - A busca pelo Cálculo do ROI

                                                                                                    A empresa onde trabalho está em busca de calcular melhor o retorno sobre o investimento de das suas campanhas do Meta Ads. A zoho junto com a Google fez um excelente trabalho e disponibilizou o cálculo desse retorno de forma maestral com o dashboard abaixo.
                                                                                                  • Email alias per task list so these tasks don't get listed under a 'General' task list that we didn't create nor use

                                                                                                    Using an email alias to add tasks is very good for forwarding emails directly into Zoho Projects however everything gets listed under a 'General' task list which is counter-intuitive. It would be good to have an email alias for each task list so we can
                                                                                                  • Can Zoho Flows repeat Actions more than once?

                                                                                                    I'm attempting to make an intentional Zoho Flow loop using the below layout. However, when "WithinLimit" condition is met, the program fails to execute the action "Get & Add Request Co..." again. Is this by design? Is Zoho Flows unable to repeat actions
                                                                                                  • Workflow to auto close Open Deals after 7 days?

                                                                                                    I want to set up a Workflow to Automatically close Deals as Lost after 7 days from their created date, (Regardless of activity or not) I am new to Zoho however I read 2 different ways to do it. 1 required to create a custom Date field and the other looked
                                                                                                  • Enable Filtering by Notes in Accounts & Other Modules

                                                                                                    I noticed that we have the option to filter by notes in the Contacts module, which is great. However, in our company, we add notes specific to an Account, and currently, there's no option to filter Accounts with notes. Can this be enabled? It would also
                                                                                                  • Zoho Marketing Automation Cannot Sync Lookiup Fields

                                                                                                    Hello all, It seems that Zoho MA cannot sync Lookup fields from the CRM. Can you confirm if this is the case? Is there a workaround? Do you know if Campaigns can sync with custom modules and also with Lookup field in the CRM? Thank you!
                                                                                                  • Mail > Columns

                                                                                                    How do I add/remove columns in Mail views? I sent individual emails to multiple coworkers which I then moved to my Coworkers Folder. When I then view the Coworkers folder, all I see is the Subject (same for all), and the sender (Me).
                                                                                                  • Undo/redo when composing Mail

                                                                                                    Where is the undo/redo button when composing mail? I've new to Zoho, I've looked, I've searched and can't find it. What am I missing?
                                                                                                  • How can I edit the Picklist History?

                                                                                                    I was working with some custom functions in CRM that inadvertently triggered unwanted changes in a picklist history for the Accounts module. It is absolutely essential for the business that I roll these changes in the subform back because they throw off
                                                                                                  • Picklist reference value in REST

                                                                                                    picklist options can be configured to have a different reference value than the displayed one, should be helpful in things like multilanguage: https://help.zoho.com/portal/en/kb/crm/customize-crm-account/translations/articles/translations is there a way
                                                                                                  • Mass replace picklist value

                                                                                                    I need to rename picklist option from "Option 1" to "Option 5". The value "Option 1" is set in about 1000 records in my CRM module. I am also using the that picklist in Reports and Workflows extensively. should I: A/ rename the option value and its reference
                                                                                                  • Foreign currencies behaviour

                                                                                                    Ladies and Gentlemen, It's really good to hear that you are developing your product, which I like a lot, but honestly, I'm sure you have much simpler issues to deal with. Foreign currencies operations have a HUGE lack in your product. Transferring from
                                                                                                  • Journey : "Added to segment" trigger doesn't work automatically

                                                                                                    Hello, I’m experiencing an issue with our Marketing Automation 2.0 integration with Zoho CRM. We have multiple segments defined in Marketing Automation, each with criteria based on field values synced from Zoho CRM. If a field value changes in Zoho CRM,
                                                                                                  • Creator Simplified #6 : Create custom buttons for multiple records using form object

                                                                                                    Hey Creators! It's learning time! Requirement Perform actions for multiple records in a single button-click using a form object. Sample Use-case In an employee management app, the HR needs to send a mail on a button-click to all employees regarding a
                                                                                                  • OAuth integration issues

                                                                                                    I'm experiencing persistent OAuth errors when trying to connect Make with Zoho API. I've tried multiple approaches but keep encountering the following issues: First error: 'Invalid Redirect Uri - Redirect URI passed does not match with the one configured'
                                                                                                  • Bulk Delete Images

                                                                                                    How do I bulk Delete Images from Zoho Campaigns. We have been using the Zoho since 2019 and can still only see the option to delete images one by one and we have a lot of old Campaign imagery we don't need anymore. Thanks!
                                                                                                  • Whatsapp Notification For Cliq

                                                                                                    We have integrated WhatsApp Business into Zoho CRM, and messages are coming through to the CRM. However, I want a notification message to be sent to the data owner in Cliq when a new message arrives. This doesn't seem possible through rules. Is there
                                                                                                  • Bigin iOS app update

                                                                                                    Hello everyone! In the latest iOS (v1.11.3) version of the Bigin app, we have introduced the following features: Initiate a conversation with a contact on the ‘Messages’ module. Introduced a templates icon in the existing WhatsApp conversation. An option
                                                                                                  • Difference between the 'field_read_only' and 'read_only' fields exposed by the Fields Meta Data API.

                                                                                                    The API documentation describes the 'field_read_only' field to indicate that a field is read-only always, implying that no user can ever get the write access for this field. The 'read_only' field's description states that its value can change depending
                                                                                                  • Zoho eCommerce frontend

                                                                                                    Questions about the Zoho eCommerce frontend 1) can different frontends (websites) be used? Zoho eCommerce is the backend with 3 or more websites. 2) how can the Zoho eCommerce frontend be customized to better fit Responsive Breackpoints? thanks best regards
                                                                                                  • Next Page