Mass Delete Records Across Modules Part II

Mass Delete Records Across Modules Part II

Hey there! Welcome back to yet another insightful post in our Kaizen series!

Picking up the thread from our last post, let's explore how to automate the process of mass deleting child records directly from the parent record's details page. This approach eliminates the need to click the Cascade Delete button repeatedly, when dealing with parent records containing over 2000 child records.

Prevent Additional Clicks to Delete 2000+ Records

Step 1 - Get the Child Record Count

Make a COQL API call in the function and get the total number of child records associated with the specific parent record.

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

Step 2 - Loops and Deluge Script

The count of child records obtained from the preceding step's response will determine the necessary iterations for executing the action. 

---> To ascertain the number of iterations, divide the total record count by 2000, and consider the nearest largest integer as the iteration count.
---> Subsequently, the entire function from the earlier post will undergo looping. Whenever the button is clicked, the placeholders (whitespaces) will be filled in accordance with the record count division, ensuring seamless delete process.
---> If there are no child records available, then it should skip the loop and delete the parent record alone. 

iterations = (response.getJSON("data").get(0).get("COUNT(id)") / 2000).ceil();
no_records_flag = false;
if(iterations == 0)
{
no_records_flag = true;
iterations = 1;
}
iterationString = "".leftPad(iterations).replaceAll(" ",",").toList().subList(0,iterations);
for each iteration in iterationString
{
if(!no_records_flag)
Handle the function code from previous post here.
}

Let us now check this from the details page of a Training Program with 7000 participants. 


Looping Constraints in Functions

The maximum file size for the function code is 2 mb and less than 1 mb is preferable for the seamless execution, which translates to approximately 6,500 lines of code. Furthermore, the function's maximum execution time is capped at 5 minutes. Any function surpassing this limit will be automatically terminated, accompanied by the error message: The limit of time has reached its maximum 300000 (milliseconds).

We trust you found this post both beneficial and informative!

Your thoughts and perspectives matter to us. If there is a topic you would like us to delve into or if you have any questions, please feel free to drop a comment below or send us an email at support@zohocrm.com.

Keep an eye out for future posts packed with similar content!

Cheers!


Additional Reading

Deluge Script
  • Number Functions in Deluge - ceil 
  • Text Functions - leftpad
Query API






    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