Guide: Learn How to Deploy Custom Function Zoho CRM and Best Practices to Optimizing Code

Guide: Learn How to Deploy Custom Function Zoho CRM and Best Practices to Optimizing Code

In this article, we will explore the "Custom Function" features in Zoho CRM, along with detailed guidance on how users can deploy these scripts across different places within the Zoho CRM organization.

Custom Function

A Custom Function in Zoho CRM is a user-defined script that automates specific business processes, and it allows a user to extend Zoho CRM’s capabilities beyond default and standard features - such as creating/updating records, sending custom notifications, or custom integration with other applications - based on triggers like Workflow Rules, Blueprints, Schedulers, Buttons, etc. Custom Functions also help tailor the CRM to fit unique organizational needs and improve efficiency.

For example:
1. Whenever an incoming email is received from a Lead, set up a Workflow rule and use a custom function to create an Event(with dynamic information) automatically.
2. User can create a Task automatically when a high-value deal is created.
3. Send out all the attached documents automatically when a deal is reached at a certain stage (i.e., Deal Won).
4. Send data to an external system whenever a Lead is created/updated in Zoho CRM.

Deploy Custom Function in Zoho CRM

Centralized section to create Custom Function and deploy across various CRM features

We have a unified section in Zoho CRM where users can create custom functions and use them in multiple CRM features.
Functions can be created for any of the categories specified below:Button
  1. Automation
  2. Schedule
  3. Related List
  4. Standalone
  5. Signals
  6. Validation Rule
Navigate to Setup (⚙️) in Zoho CRM >> Developer Hub >> Functions >> My Functions >> New Function

Function Name -> Provide a name according to script usage.
Display -> Provide a name to identify the function while association/function list.
Description -> Provide script usage overview.
Category -> Select the CRM feature (mentioned above) where function needs to be associated.



Overview Recordings: Steps to Create Custom Functions Across Zoho CRM

To create Custom Function from "Developer Hub >> Functions" -> Screencast

To create Custom Function from various CRM automation features and Field mapping as Argument:

Workflow Rule with Custom Function -> Screencast
Blueprint with Custom Function -> Screencast
Custom Related List using Function -> Screencast
Approval Process with Custom Function -> Screencast
Schedules with Custom Function -> Screencast
Button with Custom Function -> Screencast
Signal using Custom Function -> Screencast
Validation Rule with Custom Function -> Screencast   
Custom Function within Kiosk -> Screencast

Alert
If the function requires fetching information based on fields present in any module and you want to add a field directly as an argument to the script, then we would recommend you to create the function directly from the required CRM automation feature (e.g., Workflow Action, Blueprint Action, etc.) to be able to associate fields as arguments from a specific module.

TIPS: How to Optimize the Code in Custom Function

It is essential to write code in an optimized way to ensure smooth execution and avoid potential errors when working with Custom Funciton in Zoho CRM. This also helps to enhance performance, maintainability, reduce unwanted API calls and a well-structured code with optimal logic. 

Below are the best practices and tips which helps you optimise your code effectively:
  1. Avoid Unnecessary Loops:

-> If you are using a Loop (i.e., for each{} ) in a script, then try to filter the records before it enters into the loop. You could also add an IF condition inside the 'For Loop' to filter records within the loop. Also, try using the built-in List / Map methods when possible in the script instead of having loops. 
  1. Minimize API Calls

-> Whenever a user uses any Zoho API (i.e. getRecords, insert, update, etc.) in a Deluge script, it makes a call to the server in order to fetch information from the authenticated user’s account and consumes an API credit. Excess API calls (or repeated API calls within Loop) may cause API usage to exceed the allowed limits.

-> Use Bulk CRM APIs, which make bulk actions (such as bulk read or bulk write) instead of looping through individual API calls.
  1. Usage of Variables & Logging in Production

-> While writing the script, users can add info() logs to each variable to check the output for seamless functionality under the Console section within Zoho CRM IDE. After the complete code testing, we would suggest to remove or comment out logs and unused variables to make the script cleaner and easier to debug in the future. i.e., use conditional logging only for debugging purposes.

-> Ensure to use the meaningful variable names you define, which clearly reflect the data they store or the purpose they serve. This improves the readability of your script and makes debugging & collaboration significantly easier.

For example:
      // ❌ Not recommended
  1. x = input.get("Account_Name");
  2. ar = Zoho.crm.getRecordbyID("Contacts", contactID);
      // ✅ Recommended
  1. accountName = input.get("Account_Name");
  2. contact = Zoho.crm.getRecordbyID("Contacts", contactID);
  1. Use Try-Catch Blocks

-> Use try-catch blocks to handle exceptions smartly without wrapping every line in a try. Log required error messages that help trace the exact problem with the line of code. Refer to the following Help Link to know the syntax & sample code.
  1. Optimize String & Date Handling

-> Use Deluge built-in convert methods such as toDate(), toString(), dateDiff(), toText() instead of custom logic. Refer to the Deluge Built-in Methods
  1. Use ifNull() to Prevent Errors

When you use get() method in Deluge function, try using ifNull() conditional statement to avoid any errors that say "get value is null" and execution stops immediately. When you associate a function with any automation (e.g, Workflow Rules) and if such error occured, it would stop function execution for the respective record. Help LINK to know more about ifNull statement.
  1. Function Log - Success or Failures

-> Custom Function provides a "Failure" section to identify the errors which may occurs after you deployed in any of the automation feature (e.g., Workflow Rules, Blueprint, etc.). This section will list all the functions with name, entity(i.e. record), failure reason with exact failed time. This unified Failure section will help users to identify the exact problem in code and make the necessary adjustments.

Navigate to Setup (⚙️) in Zoho CRM >> Developer Hub >> Functions >> Failures

-> When a custom function is associated to any of the automation features, users can also see the complete Log of all function execution for any specific created function to track the executions (i.e. under My Functions >> 3 Dots >> Logs). This also help in a scenario where a function is executed via Workflow rule in CRM record(shows in timeline), however it didn't perform the intended actions/updates in record. In such scenario, users can check the output (info logs) & error of execution via function logs within Zoho CRM.

AlertEnsure to use the Optimised Code to avoid facing limitations related to statement execution or execution time limits. Refer to Deluge Limitations to know more information.
InfoVisit the following Help Link to understand Common Deluge Error Messages that may occur during Custom Function execution.



If you need any further clarifications, please don’t hesitate to contact partner-support@zohocorp.com.
NotesAdditionally, we kindly ask all Europe and UK Partners to reach out to partner-support@eu.zohocorp.com.


        Create. Review. Publish.

        Write, edit, collaborate on, and publish documents to different content management platforms.

        Get Started Now


          Access your files securely from anywhere

            Zoho CRM Training Programs

            Learn how to use the best tools for sales force automation and better customer engagement from Zoho's implementation specialists.

            Zoho CRM Training
              Redefine the way you work
              with Zoho Workplace

                Zoho DataPrep Personalized Demo

                If you'd like a personalized walk-through of our data preparation tool, please request a demo and we'll be happy to show you how to get the best out of Zoho DataPrep.

                Zoho CRM Training

                  Create, share, and deliver

                  beautiful slides from anywhere.

                  Get Started Now


                    Zoho Sign now offers specialized one-on-one training for both administrators and developers.

                    BOOK A SESSION







                                Quick LinksWorkflow AutomationData Collection
                                Web FormsEnterpriseOnline Data Collection Tool
                                Embeddable FormsBankingBegin Data Collection
                                Interactive FormsWorkplaceData Collection App
                                CRM FormsCustomer ServiceAccessible Forms
                                Digital FormsMarketingForms for Small Business
                                HTML FormsEducationForms for Enterprise
                                Contact FormsE-commerceForms for any business
                                Lead Generation FormsHealthcareForms for Startups
                                Wordpress FormsCustomer onboardingForms for Small Business
                                No Code FormsConstructionRSVP tool for holidays
                                Free FormsTravelFeatures for Order Forms
                                Prefill FormsNon-Profit

                                Intake FormsLegal
                                Mobile App
                                Form DesignerHR
                                Mobile Forms
                                Card FormsFoodOffline Forms
                                Assign FormsPhotographyMobile Forms Features
                                Translate FormsReal EstateKiosk in Mobile Forms
                                Electronic Forms
                                Drag & drop form builder

                                Notification Emails for FormsAlternativesSecurity & Compliance
                                Holiday FormsGoogle Forms alternative GDPR
                                Form to PDFJotform alternativeHIPAA Forms
                                Email FormsFormstack alternativeEncrypted Forms

                                Wufoo alternativeSecure Forms

                                TypeformWCAG


                                    All-in-one knowledge management and training platform for your employees and customers.

                                              Create. Review. Publish.

                                              Write, edit, collaborate on, and publish documents to different content management platforms.

                                              Get Started Now




                                                                You are currently viewing the help pages of Qntrl’s earlier version. Click here to view our latest version—Qntrl 3.0's help articles.




                                                                    Manage your brands on social media


                                                                      • Desk Community Learning Series


                                                                      • Digest


                                                                      • Functions


                                                                      • Meetups


                                                                      • Kbase


                                                                      • Resources


                                                                      • Glossary


                                                                      • Desk Marketplace


                                                                      • MVP Corner


                                                                      • Word of the Day


                                                                      • Ask the Experts


                                                                        Zoho Sheet Resources

                                                                         

                                                                            Zoho Forms Resources


                                                                              Secure your business
                                                                              communication with Zoho Mail


                                                                              Mail on the move with
                                                                              Zoho Mail mobile application

                                                                                Stay on top of your schedule
                                                                                at all times


                                                                                Carry your calendar with you
                                                                                Anytime, anywhere




                                                                                      Zoho Sign Resources

                                                                                        Sign, Paperless!

                                                                                        Sign and send business documents on the go!

                                                                                        Get Started Now




                                                                                                Zoho TeamInbox Resources





                                                                                                          Zoho DataPrep Demo

                                                                                                          Get a personalized demo or POC

                                                                                                          REGISTER NOW


                                                                                                            Design. Discuss. Deliver.

                                                                                                            Create visually engaging stories with Zoho Show.

                                                                                                            Get Started Now








                                                                                                                                  Wherever you are is as good as
                                                                                                                                  your workplace

                                                                                                                                    Resources

                                                                                                                                    Videos

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



                                                                                                                                    eBooks

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



                                                                                                                                    Webinars

                                                                                                                                    Sign up for our webinars and learn the Zoho CRM basics, from customization to sales force automation and more.



                                                                                                                                    CRM Tips

                                                                                                                                    Make the most of Zoho CRM with these useful tips.



                                                                                                                                      Zoho Show Resources