Skip to content

Instantly share code, notes, and snippets.

@arun12209
Created May 5, 2019 09:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arun12209/e33bd9992752f42e8ed3820b79cf4f18 to your computer and use it in GitHub Desktop.
Save arun12209/e33bd9992752f42e8ed3820b79cf4f18 to your computer and use it in GitHub Desktop.
MCSubscribeUnsubscribeTrg
/* 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