1

I have a similar question to this question: Preventing sandbox from sending Workflow emails to "Additional Emails" But the solution provided there is not the solution.

In my org, I want to test a WFR, that does send an email alert, however, I don't want the additional emails to receive the alert.

If I change the 'Email deliverability' to System Only, no emails will be sent.

But if I change it to 'all email', every one will get the alert, as well as the 'Additional Emails'.

How can I, programmatically, mask/remove/disable these alerts from sandbox (assuming we create multiple sandboxes, and have these 'additional emails' in many places)?

1 Answer 1

1

The only way to do this programmatically is to have some apex/outside code that calls the sandbox's Tooling API and updates each Workflow Alert to remove the value in the additional emails field. This is probably assuming you never need to "add" those additional emails back.

I'm going to show each step (the calls), but you can do this all through Apex. I recommend leveraging the Composite Resources in the REST API to make sub-requests and drastically reduce the amount of API calls. The major pain is you need the Metadata field returned for WorkflowAlert and that only occurs when 1 record is queried so you end up needing to do a lot of calls. Hence, why being able to do 25 sub-requests can really help this be more efficient (4 calls to query and update 100 alerts vs. 100 calls).

enter image description here

  1. Use the query resource in the Tooling API to get all your WorkflowAlerts with additional emails.
  2. Remove any value in the CcEmails field under Metadata as that is where the additional emails are stored.
  3. Now, do an update using the Id returned from the query to remove the CcEmails. The response from the query should actually give you the url to call to update in the url property of the attributes.

To be more specific about the endpoints

Query resource in Tooling API (GET)

/services/data/v50.0/tooling/query/?q=SELECT+Id,CcEmails,Metadata+FROM+WorkFlowAlert+WHERE+CcEmails+!=NULL+LIMIT+1

This'll return a response like so:

{
  "size" : 1,
  "totalSize" : 1,
  "done" : true,
  "queryLocator" : null,
  "entityTypeName" : "WorkflowAlert",
  "records" : [ {
    "attributes" : {
      "type" : "WorkflowAlert",
      "url" : "/services/data/v50.0/tooling/sobjects/WorkflowAlert/0000000000"
    },
    "Id" : "00000000000000",
    "CcEmails" : "[email protected]",
    "Metadata" : {
      "ccEmails" : [ "[email protected]" ],
      "description" : "Testing alert",
      "protected" : false,
      "recipients" : [ {
        "field" : null,
        "recipient" : "[email protected]",
        "type" : "user"
      } ],
      "senderAddress" : "[email protected]",
      "senderType" : "OrgWideEmailAddress",
      "template" : "Email_Alert_Email_Templates/Some_Template",
      "urls" : null
    }
  } ]
}

Make a PATCH call to the URL returned in the response above for each record.

/services/data/v50.0/tooling/sobjects/WorkflowAlert/000000000000(Id of alert)

Note: You need to include the fields below and should make sure to copy from the initial response so the values you're not planning to change don't change.

{
    "Metadata" : {
      "ccEmails" : [ "" ],
      "description" : "Testing Alerts",
      "template" : "Email_Alert_Email_Templates/test",
      "senderType" : "OrgWideEmailAddress",
      "senderAddress" : "[email protected]",
"recipients" : [ {
        "field" : null,
        "recipient" : "[email protected]",
        "type" : "user"
      } ]
      
    }
  
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .