Friday, January 10, 2025
0.6 C
London

Trigger to blacklist domain name for sending email

You now have an awesome Salesforce instance that you use for your sales and marketing purposes. Your instance sends hundreds of mails weekly, many of them to prospective clients. But sometimes in a fast sales machine environment where your sales guys would be sending hundreds of bulk mails daily, it becomes very difficult to make sure that your sales agents do not send mails to some specific domains, or that they cross-check their lists every time from a common no-mailing lists.

You would come across cases like these in your business life-cycle, where you don’t want your sales prospectors to send mails to specific email addresses or even to specific domains, like unsubscribe markers, present clients, competitors, etc. Unfortunately it is very difficult to make sure through a process that your users don’t send mails to these domains, specifically for cases where your fellow SFDC users would be sending mails in bulk for marketing or prospecting.

The most simple solution is to make sure that your Salesforce instance itself is not able to send mails to said domains. Do this is not that difficult. You would just have to write a trigger.

In your salesforce org, if you want to blacklist domain name on which you don’t want to send mail from salesforce then you can use the following trigger to do this…

trigger BlackListEmailAddress1 on EmailMessage (before insert) {
    for(EmailMessage message: Trigger.New)
    {
        if((message.ToAddress.contains('gmail')) && message.Incoming == false )
        {
            message.addError('Email Alert: You have selected a receipient email from one of the blacklisted doamins please use another email address and try again');
        }
        if((message.ToAddress.contains('yahoo')) && message.Incoming == false )
        {
            message.addError('Email Alert: You have selected a receipient email from one of the blacklisted doamins please use another email address and try again');
        }
    }
}

In this trigger, we have blocked only two domains names Gmail and Yahoo. Your users won’t be able to send any mails that have Gmail or Yahoo in their domain name. If you need to block any specific ID or another domain, then all you have to do is add a new ‘if’ condition like

if((message.ToAddress.contains('example.com')) && message.Incoming == false )

This will work for all the objects where we have the option to send an email, like contacts, leads, custom objects, etc.

Hot this week

Unlock Savings with VEU Rebates for Split Air Conditioning Systems

As energy efficiency becomes a growing priority, consumers are...

The Future Of Development On Salesforce Is With Lightning Experience

As per the Salesforce release of 2017 a number...

Discover the Magic of Cortiez: Tracksuits Redefined

When it comes to excellent streetwear, Cortiez isn’t just...

Perforated Sheet Suppliers in Dubai: Your Guide to High-Quality Metal Solutions

Dubai, a bustling hub of innovation and construction, is...

Mobile Salesforce Solution That is Perfect For You

Let us just take a quick tour down memory...

Topics

Unlock Savings with VEU Rebates for Split Air Conditioning Systems

As energy efficiency becomes a growing priority, consumers are...

The Future Of Development On Salesforce Is With Lightning Experience

As per the Salesforce release of 2017 a number...

Discover the Magic of Cortiez: Tracksuits Redefined

When it comes to excellent streetwear, Cortiez isn’t just...

Perforated Sheet Suppliers in Dubai: Your Guide to High-Quality Metal Solutions

Dubai, a bustling hub of innovation and construction, is...

Mobile Salesforce Solution That is Perfect For You

Let us just take a quick tour down memory...

The Essentials Jacket A Timeless Statement of Style and Comfort

In the fast-paced world of style, where fads arrive...

Why Carsicko Is Your Ultimate Wardrobe Essential

Carsicko is not just apparel. It’s a vibe, a...

Why Madhappy Clothing Is a Wardrobe Essential

Madhappy Clothing is a revolutionary brand that masterfully combines...

Related Articles

Popular Categories