AnsweredAssumed Answered

How to detect email address invalid/opt-out changes in 7.5 and above?

Question asked by Chad Hutchins on Apr 11, 2016
Latest reply on Apr 25, 2016 by Chad Hutchins

Hello, it seems in Sugar 7.5 and above the email optout/invalid data available in the before_save and after_save logic hooks has changed for the Contacts module, however our code works exactly how it has in the past for the Targets and Leads module. What we'd like to accomplish is to have a logic hook that detects when a Contact's primary email address invalid or opted out value changes.


Before Sugar 7.5, we could do all of this work in our Contacts before_save and after_save logic hooks. But it appears now the email address record is saved **before** the Contacts before_save logic hook starts, so there's no way to detect the change in the Contacts logic hook.


I've tracked down when this started, and it was in the initial release. In modules/Contacts/ContactsApiHelper.php, you'll see a new line was added: $bean->emailAddress->populateLegacyFields($bean);


This is what is triggering the email save before the Contacts before_save can even begin. I could see this going either way for if this is a bug or not. A couple questions/clarifications:


1. Is this how we can expect this to act going forward? Where changes to the email address are saved before the Contact record save begins? If so, what's the best way to detect email address invalid/optout changes?


2. If the answer to #1 is yes, then should we expect the email invalid/optout flags to work the same for the Leads and Targets module? Or will this be only a Contacts module specific thing? I'm not sure how the hierarchy but it seems the code added to modules/Contacts/ContactsApiHelper.php should be added to the include/SugarObjects/templates/person/PersonApiHelper.php so that all "Person" modules have this same functionality.