You need to sign in to do that
Don't have an account?
John Neilan 2
Email Contacts from Process
Hello,
I am trying to invoke an Apex method from a Process that will email a certain set of Contacts associated with an Account that gets marked via a custom field. I have the class below, but nothing is happening when I change the Account. The Process is fired, but nothing happens from the Apex. Does anyone know why?
I am trying to invoke an Apex method from a Process that will email a certain set of Contacts associated with an Account that gets marked via a custom field. I have the class below, but nothing is happening when I change the Account. The Process is fired, but nothing happens from the Apex. Does anyone know why?
public class VF_ClassComplCustEmail { @InvocableMethod public static void SendEmailCompl(List<Id> acctId){ EmailTemplate templateId = [SELECT Id FROM EmailTemplate WHERE Id = '00XL0000000IePcMAK']; List<Contact> complCont = [SELECT Id, Non_Comp_Contact__c, Email FROM Contact WHERE Id in: acctId AND Non_Compl_Contact__c = TRUE]; List<Messaging.SingleEmailMessage> allmsg = new List<Messaging.SingleEmailMessage>(); for(contact con : complCont) { Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); mail.setTemplateID(templateId.Id); mail.setTargetObjectId(con.id); mail.setSaveAsActivity(false); allmsg.add(mail); } Messaging.sendEmail(allmsg,false); } }
On which object your process is ?
If it is on account then below query retuen nothing.
List<Contact> complCont = [SELECT Id, Non_Comp_Contact__c, Email FROM Contact WHERE Id in: acctId AND Non_Compl_Contact__c = TRUE];
If you process on account then use this query.
List<Contact> complCont = [SELECT Id, AccountId, Non_Comp_Contact__c, Email FROM Contact WHERE AccountId in: acctId AND Non_Compl_Contact__c = TRUE];
Mark it as solution if this helps you out.
Thanks
Naresh
You need to pass account object. See the below code. Mark it as solution if this helps you out.
Thanks
Naresh