Step 1: Go to Setup -> Automation -> Workflow Rules
Step 2: Click "Create Rule" and you will see the "Create New Rule" popup:
Set the "Module" to your custom module.
Give your rule a meaningful name, for example "ZE_CRM_Toolbox_On_Edit_{{CUSTOM_MODULE_NAME_HERE}}_Phone_Number"
Click "Next".
Select to "Execute this workflow rule based on": "Record Action" -> then select "Edit" -> then select "Specific field(s) gets modified".
Tick "Repeat this workflow whenever a tenancy is edited"
A new input will popup with an input next to "When". In that input, select the Phone number field you want to act as the trigger, then for "is modified to", select "not empty":

Click "Next".
Step 4: Select "All {{Custom Module Name Here}}" and click "Done":
Step 5: Click Instant Actions -> Function:
Step 7: Set the "Function Name" and "Display Name" to the same value as the Workflow Rule and click "Create":
Step 8: Edit the code
The code editor should load with code that looks like this (but with your Function Name after "automation."):
Paste the below code in between the { } (curly braces) and change "Tenancies" to the API_Name of your Custom Module (you can find the Custom Module API Name under "Setup" -> "Developer Hub" -> "APIs and SDKs" (then click on the "API name" tab at the top, and scroll down to your custom module -> the api name is the value in the second column):
- //
- // CHANGE THIS BELOW VALUE TO THE API NAME OF YOUR CUSTOM MODULE:
- Module_API_Name = "Tenancies";
- //
- // DO NOT EDIT THE CODE BELOW THIS LINE:
- Script_Name = "ZE_CRM_Toolbox_On_Edit_Lead_" + Module_API_Name + "_Number";
- //
- Return_Map = Map();
- Error_Map = Map();
- //
- try
- {
- // USE STANDALONE FUNCTION TO VALIDATE RECORD PHONE NUMBERS
- response = zelogger.ZE_CRM_Toolbox_Execute_Action_On_All_Record_Fields(Module_API_Name,Record_ID,"validatePhone");
- //
- if(response == null || response.containKey("SUCCESS") == false)
- {
- Error_Map.put("Error running automatic Phone Number Validation",response);
- }
- else
- {
- Return_Map.put("SUCCESS","Phone Number Validation Automation Completed Successfully");
- }
- //
- }
- catch (e)
- {
- Error_Map.put("Catch Error",e);
- }
- //
- //
- if(Error_Map.isEmpty() == false)
- {
- Return_Map.put("ERRORS",Error_Map);
- //
- zelogger.Create_ZE_Log(Record_ID,Module_API_Name,"Error",Return_Map,"Low",Script_Name);
- }
- //
- info Return_Map;
Step 8: Add the "Record_ID" as the "Arguments" to the Workflow Rule:
Click on the ( x ) tab on the top right-hand corner, under ⓘ and set the "Record_ID" as the custom module Id (press "#" to open the "Add Merge Field" popup, then select the Module [usually first option] then select the field as the Record ID [usually the first option]:
Step 9: Click "Save and Associate" and then on the next screen click "Save" and you're done!