0

I am writing a workflow rule to send an email to the Opportunity owner whenever an Opportunity is assigned to users under certain profiles. My workflow rule looks something like this:

Evaluation Criteria: Evaluate the rule when a record is created, and every time it's edited

AND(CASE(Owner.Profile.Name, "Advisor", 1, 
"Super User", 1, 
"Assistant to Advisor", 1, 0) == 1, 
IsClosed = FALSE, 
ISNEW() || ISCHANGED(OwnerId), 
RecordType.DeveloperName = 'Referral' 
)

Immediate Workflow Action: Email Alert

In our full sandbox all the users have correct email address and email deliverability is also set to all emails because our training happens in this sandbox. Due to this, the users are getting emails of Opportunity assignment for Sandbox too and we want to avoid that. How can I use a custom setting so that only the users I specify in that if assigned as an Owner of the Opportunity should get an email.

Following workflow rule does not work because it still sending email to the owner of the Opportunity when the custom setting "Send_Email_Opportunity_Owner__c" is set to true for the running user.

AND(CASE(Owner.Profile.Name, "Advisor", 1, 
"Super User", 1, 
"Assistant to Advisor", 1, 0) == 1, 
IsClosed = FALSE, 
ISNEW() || ISCHANGED(OwnerId),
$Setup.Send_Email_Opportunity_Owner__c.Allow_Email_Send__c = TRUE, 
RecordType.DeveloperName = 'Referral' 
)

Can this even be done?

1

Well, old-school magic to rescue.

  1. Create a script - data loader or Apex batch, to suffix "_test" to all user emails
  2. Include logic in script to exclude provided users (if the user list is big). Else, revert select user emails post the process

This method almost never fails :). And of course, I know you and most others know that.

As others pointed out, there are no other reliable ways of filtering sandbox "internal" emails. We have experimented with mailbox rules / evaluated email relay, additional flags and permanent config changes to prevent emails to marked users etc., but only the above method stuck across multiple instances (over few years; across dev/support team members with varying degrees of expertise/experience).

| improve this answer | |
1

As far as I know, you won't be able to achieve that using hierarchical custom settings because it checks for the logged in user and not the owner of the record.

One other alternative I can think of is to have a custom field created on User object and use that field in your workflows.

Create a boolean field called Send Workflow Emails on User object, and use this field in workflows to decide whether to send emails to that user or not. Your workflow rule then would be

AND(
    CASE(
        Owner.Profile.Name, "Advisor", 1, 
                "Super User", 1, 
                "Assistant to Advisor", 1, 0
        ) == 1, 
        IsClosed = FALSE, 
        (ISNEW() || 
        ISCHANGED(OwnerId)), 
        Owner.Send_Workflow_Emails__c = TRUE, 
        RecordType.DeveloperName = 'Referral'
)

This way, you can make sending emails from workflows configurable.

Note : Make sure that you remove this conditions from workflows and delete the field on User object before moving to Production.

| improve this answer | |
  • Thank you for the response and lesson of indentation. Small things go a long way. – Json Bourne Shell Apr 23 '19 at 16:58
0

You can turn off email sent of your environment by the following steps

Setup > Email Administration > Deliverability

There you can find 3 options

  1. No access (Turn off sending all types of emails)
  2. System email only (Allow only system emails i.e. user password reset etc)
  3. All email (Allow all types of email)
| improve this answer | |
  • "In our full sandbox all the users have correct email address and email deliverability is also set to "all emails" because our training happens in this sandbox." – Json Bourne Shell Apr 23 '19 at 4:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.