I understand that visualforce templates cannot be mass emailed. Is it possible to put a single email method in a loop? I also understand that lists in loops are bad!
I have tried to cut up this post to suit the requirement.
APEX:
public PageReference sendEmail(){
ID currentRecordID = ApexPages.CurrentPage().getparameters().get('ID');
emailTemplate et = [Select id from EmailTemplate where name = 'ABS Trainer - Unit Confirmation - Online' LIMIT 1];
List<Contact> contactNames = [SELECT id, name FROM Contact WHERE AccountId =: currentRecordID LIMIT 200];
for (String obj : contactNames){
contact = [SELECT Id,name,email FROM Contact WHERE name =:obj];
for(Integer i=0; i < contact.size(); i++){
Messaging.SingleEmailMessage email = new Messaging.SingleEmailMessage();
email.setTargetObjectId(contact[i].Id);
email.setTemplateId(et.id);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] { email });
}
}
ApexPages.addMessage(new ApexPages.message(ApexPages.severity.INFO,'Email Sent Successfully'));
return null;
}