Workflow Rule for Custom Module Auto Email Validation

Workflow Rule for Custom Module Auto Email Validation


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".

Step 3: On the next Popup:

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 6: Click "Configure Action", then click "Write your own"


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":
  1. //
  2. // CHANGE THIS BELOW VALUE TO THE API NAME OF YOUR CUSTOM MODULE: 
  3. Module_API_Name = "Tenancies";
  4. Action = "validateEmail"; // OR "verifyEmail"
  5. //
  6. // DO NOT EDIT THE CODE BELOW THIS LINE:
  7. Script_Name = "ZE_CRM_Toolbox_On_Edit_" + Module_API_Name + "_Email_Address";
  8. //
  9. Return_Map = Map();
  10. Error_Map = Map();
  11. //
  12. try 
  13. {
  14. // USE STANDALONE FUNCTION TO VALIDATE/VERIFY RECORD EMAIL ADDRESSES
  15. response = zelogger.ZE_CRM_Toolbox_Execute_Action_On_All_Record_Fields(Module_API_Name,Record_ID,Action);
  16. //
  17. if(response == null || response.containKey("SUCCESS") == false)
  18. {
  19. Error_Map.put("Error running automatic " + Action ,response);
  20. }
  21. else
  22. {
  23. Return_Map.put("SUCCESS", Action + " Automation Completed Successfully");
  24. }
  25. //
  26. }
  27. catch (e)
  28. {
  29. Error_Map.put("Catch Error",e);
  30. }
  31. //
  32. //
  33. if(Error_Map.isEmpty() == false)
  34. {
  35. Return_Map.put("ERRORS",Error_Map);
  36. //
  37. zelogger.Create_ZE_Log(Record_ID,Module_API_Name,"Error",Return_Map,"Low",Script_Name);
  38. }
  39. //
  40. 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!