0

When updating contacts/leads I'd like to be able to check against a list of 10 (and growing) emails. If the record being updated/created matches one of the emails on the list, I want to throw a validation error e.g. "Person is blacklisted".

My initial thought was to just have a large validation rule on the Contact and Lead objects that checks the whole list of emails in the rule criteria i.e. OR(CONTAINS(email,"dave@gmail.com"),CONTAINS(email,"dave1@gmail.com"),etc.,etc.

However, the list of emails grows by about 1 a month, and I want to avoid having to iterate this formula every time I want to add an email to the list.

How can I check a Contact/Lead record updates against a list of emails in a more efficient way? Queues?

P.S. I've had the Individual object suggested to me, but its functionality is limited, also, I don't believe it's necessary as my email list size is about 10 right now.

0

You could store the list of emails in another object and then have a trigger on your Contact and Lead object that does a check against this list.

High level code:

trigger myContactTrigger on Contact (before insert, before update)
{

    BlackList__c[] recs = [Select Email__c From BlackList__c];
    Set<String> emls = new Set<String>();

    for(BlackList__c r : recs)
    {
        emls.add(r.Email__c)
    }

    for(Contact c : Trigger.new)
    {
        if(emls.contains(c.Email))
        {
            c.addError('This is a Blacklisted Email');
        }
    }
}

  • Would love to implement if I had more knowledge of triggers. How many lines would it be approximately? – Nivi Oct 21 at 21:11
  • @Nivi I have updated my answer to be a working example – Bryan Anderson Oct 22 at 13:16
  • Thank you. Do you have a link to any documentation about how to implement in org? I want to try this solution. – Nivi Oct 31 at 18:44
  • Not specifically, this is a valid trigger. The only thing you would have to implement would be a custom object called BlackList__c – Bryan Anderson Nov 1 at 13:34

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.