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}}_Email_Address"
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 up to 5 Email Address fields 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
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):
It is currently set to "Validate" email addresses. If you want to "Verify" email addresses, change the "Action" from "validateEmail" to "verifyEmail":
- //
- // CHANGE THIS BELOW VALUE TO THE API NAME OF YOUR CUSTOM MODULE:
- Module_API_Name = "Tenancies";
- Action = "validateEmail"; // OR "verifyEmail"
- //
- // DO NOT EDIT THE CODE BELOW THIS LINE:
- Script_Name = "ZE_CRM_Toolbox_On_Edit_" + Module_API_Name + "_Email_Address";
- //
- Return_Map = Map();
- Error_Map = Map();
- //
- try
- {
- // USE STANDALONE FUNCTION TO VALIDATE/VERIFY RECORD EMAIL ADDRESSES
- response = zelogger.ZE_CRM_Toolbox_Execute_Action_On_All_Record_Fields(Module_API_Name,Record_ID,Action);
- //
- if(response == null || response.containKey("SUCCESS") == false)
- {
- Error_Map.put("Error running automatic " + Action ,response);
- }
- else
- {
- Return_Map.put("SUCCESS", Action + " 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.
Step 9: Click "Save and Associate" and then on the next screen click "Save" and you're done!