4

I am trying to track bounce emails on contact object. For this, if an email got bounced, there are few fields on the contact object which will be updated by system itself. Those fields were

IsEmailBounced

EmailBouncedDate

EmailBouncedReason

But I want to fire a workflow when any of these fields get updated in order to update a Status to Bounced. But I have observed, when email got bounced, the above fields are getting changed, but it is not triggering my workflow. Is there a chance to achieve this? Like while change in the system fields has to fire an workflow or trigger.

5

As per this article by Cory Cowgill "These fields are only visible in Apex code. You can't create a workflow rule / field update to do this unfortunately. Luckily, the Apex code is pretty simple. For example, below I added a boolean flag to Contact call "Invalid Email". Whenever I update this field, be it from the UI or a Web Service call from a 3rd party email system, the Bounce Alert functionality fires."

Sample Code to set the Email Bounced Alerts in Apex:

trigger ContactTrigger on Contact (after delete, after insert, after undelete, 
after update, before delete, before insert, before update) 
{
    if(Trigger.isBefore)
    {
        for(Contact contact : trigger.new)
        {
            if(contact.EmailBouncedDate == null && contact.EmailBouncedReason == null && contact.Invalid_Email__c == true)
            {
                contact.EmailBouncedDate = DateTime.now();
                contact.EmailBouncedReason = 'Invalid Email Address Set By User';
            }
            if(contact.Invalid_Email__c == false)
            {
                contact.EmailBouncedDate = null;
                contact.EmailBouncedReason = null;
            }
        }
    }
}

Hope this helps.

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.