Thursday, January 30, 2020

Fetch All Workflow Email Alert Details Related to Object Using Tooling API

Through this blog, I will sharing script which can help to get complete information about all the email alerts configured in Salesforce using workflow rules for any sObject.

Imagine a scenario in which you need to extract all email alert configured or created for different workflow rules for specific object so that it can be reviewed or analyzed. If you do this activity manually then you have to open each workflow email alert and note down details like recipient, ccEmails, senderAddress, email template etc. This will be very hectic if you have lots of email configured.

In order to solve this scenario, I am using Tooling API through which we can get complete details about workflow email alert. Through apex script, we can generate these details and send email (with csv file as attachment) to user with all details.

First of all, inorder to parser JSON response, we need to create apex class (SK_EmailAlertJSONParser) which will act as parser for JSON. After this we can run the script in developer console and user will get email with all information regarding email alert.


Below is snapshot of csv file that we will receive after running above script in developer console.
I have specified objectId as "Contact". For custom object, specify 15 digit or 18 digit id.


This script can be used to fetch information from other salesforce org also. Suppose you don't want to deploy this script in production, then save SK_EmailAlertJSOnParser class in sandbox and in developer console (using execute anonymous window)  just specify the domainUrl for production and sessiond id production for admin user.

Don't forget to add domainUrl in remote site settings before running this script in execute anonymous window in developer console.

Hope this will help!!1

7 comments:

  1. Thanks for sharing this useful information, really helped me a lot. In the recent announcement from Salesforce, I heard they have launched LWC Local Development Beta program. Can you please tell me more about that. As a Salesforce consulting partner, It's a great news for us.

    ReplyDelete
  2. Hi there, I read your blogs on a regular basis. Your humoristic style is witty, keep it up! Thank You for Providing Such a Unique and valuable information, If you are looking for the best Serp Api, then visit SERP House. I enjoyed this blog post.

    ReplyDelete
  3. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck. active response training

    ReplyDelete
  4. Hi Please help why is it returing only one row ..I ran this is anonymous window. and getting only 1 row ..
    string sessionId= UserInfo.getSessionID();
    string domainUrl=URL.getSalesforceBaseUrl().toExternalForm();
    system.debug('********domainUrl:'+domainUrl);
    string objectId ='Email Alerts'; //for custom objects, provide 15 digit or 18 digit object id
    HttpRequest req = new HttpRequest();
    req.setHeader('Authorization', 'Bearer ' + sessionId);
    req.setHeader('Content-Type', 'application/json');
    req.setEndpoint(domainUrl+'/services/data/v47.0/tooling/query/?q=select+id,SenderType,templateId+from+WorkflowAlert');
    req.setMethod('GET');
    Http h = new Http();
    HttpResponse res = h.send(req);
    system.debug(JSON.serializePretty(res.getBody()));

    I need to get all the email Additional Email field how to do that .. Also kindly help is this class needs to execute only in anonymous window.. my require is to fetch all the workflowemailalert additional email field and update it with .invalid suffix in lower sandbox.. how to achive the whole flow please help

    ReplyDelete
  5. This is a wonderful article, Given so much info in it, These type of articles keeps the users interest in the website, and keep on sharing more ... good luck. g licensing

    ReplyDelete
  6. Can you please help me to update ccEmail field with the code please this is very urgent

    ReplyDelete
  7. Hey what a brilliant post I have come across and believe me I have been searching out for this similar kind of post for past a week and hardly came across this. Thank you very much and will look for more postings from you. hotmail

    ReplyDelete