Thursday, January 9, 2025
4.2 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

Know The New Salesforce Lightning And Its Features

After Salesforce Classic, when the company released its new...

Web Applications for Remote Work and Collaboration Tools

In recent years, the world has seen a significant...

Indian Casino Trends to Watch in 2025

The world of casinos in India is changing fast,...

Brandy Market Size, Share & Trends 2025-2034

The brandy market is experiencing significant growth, especially in...

Essentials Clothing

The Birth Of Essentials ClothingThe Ideas Behind Essentials FashionEssentials...

Topics

Know The New Salesforce Lightning And Its Features

After Salesforce Classic, when the company released its new...

Web Applications for Remote Work and Collaboration Tools

In recent years, the world has seen a significant...

Indian Casino Trends to Watch in 2025

The world of casinos in India is changing fast,...

Brandy Market Size, Share & Trends 2025-2034

The brandy market is experiencing significant growth, especially in...

Essentials Clothing

The Birth Of Essentials ClothingThe Ideas Behind Essentials FashionEssentials...

Sandalwood Dream Perfume: The Ultimate Blend for a Captivating Aura

There’s something undeniably enchanting about a well-chosen fragrance. It...

Women’s Winter Pret Trends: Embrace the Season with Luxury Pret Online

Shop luxury pret online: Exclusive Collections & High-End Fashion | Discover Trendsetting Styles & Premium Quality Apparel Today

What Makes a 10kW Solar System Ideal for High-Traffic Areas?

The global transition toward renewable energy has redefined how...

Related Articles

Popular Categories