Today, I was working on a requirement which queries public group and sends an email to the users(group members) with an attachment from the custom object record and it was implemented using APEX code. I wanted to test using Execute Anonymous option in Developer Console before I call the code using process builder. When I tried executing it in Developer Console, it was throwing Sending Request – Execution Failed error. I could not figure out the reason for it, but I realised that using workbench to execute Anonymous APEX code is better than Dev Console since your code, results are displayed in the same page and you can set the log level too.

Steps to execute APEX in Workbench:

a. Login to https://workbench.developerforce.com
b. Select Sandbox or Production(obviously, we will test the code in Sandbox first)
c. Then system will ask you to login to Salesforce
d. Once logged in, select “Apex Execute” in Jump to option
e. Paste your code in the text box and click on Execute button.
f. System will show the results on the same page. You can select the appropriate Log category and Log level too.

In the future post, I will write about creating a flow to query the public group based on the name and send an email to the group members(role based members).