Trigger SendEmail on Invoice__c (after insert, after update)
{
List<Id> ContIds = new List<Id>();
for(Invoice__c invoc :trigger.new)
{
if(invoc.Status__c=='Dispatch')
{
ContIds.add(invoc.Contact__c);
}
}
if(ContIds.size() > 0){
EmailTemplate e = [Select e.Body, e.Id, e.Name, e.Subject from EmailTemplate e where id='00XO0000000LwRu'];
Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();
mail.setTargetObjectIds(ContIds);
mail.setTemplateId(e.Id);
Messaging.sendEmail(new Messaging.MassEmailMessage[] { mail });
}
}
No comments:
Post a Comment