function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rebekah LillyRebekah Lilly 

tooling api

Hi, I would like to be able to create an Apex class that uses the Tooling API to see if a User (by ID or Email Address) is a recipient on email alerts or if their ID or Email Address is used in any metadata fields. I have written HTTP Callouts before, but having a bit of trouble figuring out how to access use the Tooling API to access my own org. I can't seem to figure out how to scan all email alerts for the main recipient. I can see the ccemails on the WorkFlowAlert object, but where is the main recipient? 
VinayVinay (Salesforce Developers) 
Hi Rebekah,


You can use Tooling API for this and query the WorkFlowAlert table from developer console:
  • Open Developer Console 
  • Click on Query Editor
  • Check "Use Tooling API"
  • Set query, e.g. SELECT Id, DeveloperName, Description, CcEmails, SenderType, TemplateId FROM WorkFlowAlert WHERE CcEmails like '%test.user@email.com%'
  • Click Execute

https://salesforce.stackexchange.com/questions/121226/tooling-api-workflow-email-alert-update

Please mark as Best Answer if above information was helpful.

Thanks,
Rebekah LillyRebekah Lilly
Hi Vinay,

Yes, I am able to see the information using the Tooling API in the Developer Console. 

What I really want to do is retrieve this information via Apex. Background ask is to input a user name and retrieve references to that user in our custom fields as well as dashboards where they are the running user, users they manage, etc. It is very important to our offboarding procedures to know where a particular user is referenced. I want to include email alerts they are recipients on as well since they will need to be replaced on the alerts before I can deactivate them.

I have written an Apex class in which I do an http callout and get all the ID's from WorkFlowAlert. 

Then, I can successfully take those ID's and query the metadata for each one to see if the email address of the user is the recipient or one of the ccemail recipients.

However, we have more over 150 email alerts and I am having to query the metadata for each WorkFlowAlert individually, so my process fails due to "too many callouts".

Is there a way to generically scan (like a SOSL query) that I am missing when using the Tooling API?

I am stuck trying to figure how to work around the callout limitation because I would really like to do this in a flow. I have built a nice user-friendly flow that shows neatly formatted results for the user/email that is leaving and optionally allows sending emails to the persons who can supply replacement information. But, this 100 callout limitation is a stumbling block with having to process the metadata for each WorkflowAlert individually. It works great when I limit my workflowalert, but I really need to check them all to see if the user email is referenced.

Any suggestions are greatly appreciated.

Thanks,
Rebekah
 
Rebekah LillyRebekah Lilly
I think I have figured it out. I can use the compositeRequest and send the WorkflowAlert Id's in sets of 25 to request the relevant details. Initial testing seems to work. Very cool new thing I learned this week :)