Created
May 5, 2019 09:06
-
-
Save arun12209/e33bd9992752f42e8ed3820b79cf4f18 to your computer and use it in GitHub Desktop.
MCSubscribeUnsubscribeTrg
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Name:MCSubscribeUnsubscribeTrg | |
* Description: On contact record insert/update subscribe/unsubscribe member in Mailchimp list. | |
* Created Date: 05/05/2019 | |
* Last ModifiedDate : 05/05/2019 | |
* Created By: Arun Kumar | |
*/ | |
trigger MCSubscribeUnsubscribeTrg on Contact (after insert, after update) { | |
if(trigger.isAfter && trigger.isUpdate){ | |
system.debug('Contact Email has Opted Out: '); | |
set<string> contactEmailSet=new set<string>(); | |
for(contact co:trigger.new){ | |
if(co.HasOptedOutOfEmail==true && co.email!=null){ | |
contactEmailSet.add(co.email+'|false'); | |
} | |
if(co.HasOptedOutOfEmail==false && co.email!=null){ | |
contactEmailSet.add(co.email+'|true'); | |
} | |
} | |
system.debug('Contact Email has Opted Out: '+contactEmailSet); | |
if(contactEmailSet.size()>0){ | |
if (System.isFuture() || System.isBatch()){ // If Trigger initiated through future and Batch Process, | |
} | |
else{ | |
MCSubscribeUnsubscribeHelper.doSubscribeUnsubscribe(contactEmailSet); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment