You need to sign in to do that
Don't have an account?

how to send an email when contact campaign member or lead gets updated
I have written a code where when a lead or contact is added to campaign, i need to check on some coditon and if they satisfy send out a survey link as an email and after that update last survey date field and type to a specific value. This is what i have so far, but not sure how to add email code without hitting email limit....
public class CampaignMembers_Hanlder { public static void getCampaignMembers(List<CampaignMember> campaignMember) { Set<id> setOfContactIds = new Set<id>(); Set<id> setOfLeadIds= new Set<id>(); if(campaignMember!=null){ for(CampaignMember varCampaignMember: campaignMember){ if(varCampaignMember.ContactId!=null){ setOfContactIds.add(varCampaignMember.ContactId); } if(varCampaignMember.leadId!=null){ setOfLeadIds.add(varCampaignMember.leadId); } } for(Contact varContactRecord:[Select id, HasOptedOutOfEmail,Last_Survey_Sent_Date__c,account.Licensed_Mainframe__c, Last_Survey_Sent_Type__c from contact where id IN:setOfContactIds]) { If(varContactRecord.HasOptedOutOfEmail==false && varContactRecord.account.Licensed_Mainframe__c =='Active'){ if(varContactRecord.Last_Survey_Sent_Date__c!=null && varContactRecord.Last_Survey_Sent_Date__c>= system.today()-60){ String[] toAddresses = new String[] {'user@acme.com'}; } } } for(Lead varLeadRecord: [Select id, HasOptedOutOfEmail, Last_Survey_Sent_Date__c, Last_Survey_Sent_Type__c, SFDC_Account__r.Licensed_Mainframe__c from Lead WHERE id IN:setOfLeadIds]){ If(varLeadRecord.HasOptedOutOfEmail==false && varLeadRecord.SFDC_Account__r.Licensed_Mainframe__c =='Active'){ if(varLeadRecord.Last_Survey_Sent_Date__c!=null && varLeadRecord.Last_Survey_Sent_Date__c>= system.today()-60){ String[] toAddresses = new String[] {'user@acme.com'}; } } } } } }