You need to sign in to do that
Don't have an account?
Naveen Dhanaraj
write a class and trigger to send an email after creating a patient record and once appointment has been created it should send an email
I have patient and appointment as an object in Hospital management system. if the appointment has been created it should send an email that your appoinment has been confirmed
public static void sendemailtoPatient(list<Appointment__c> appointments){
EmailTemplate et=[Select id from EmailTemplate where name='Appointment: New Customer Email'];
list<Messaging.SingleEmailMessage> emails = new list<Messaging.SingleEmailMessage>();
//To store patient Id
set<Id> setPatientId = new set<Id>();
if(appointments.size()> 0) {
for(Appointment__c iterator : appointments) {
if(iterator.Patient__c != null) {
setPatientId.add(iterator.Patient__c);
}
}
}
//fetch the patient records for whom an email needs to be sent
if(setPatientId.size()>0) {
list<Patient__c> Patients = [Select Id,Email__c from Patient__c where Id IN : setPatientId];
for(Patient__c pat : Patients){
if(pat.Email__c != null){
Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();
singleMail.toaddresses(pat.Email__c);
singleMail.setTemplateId(et.Id);
emails.add(singleMail);
}
}
}
Messaging.sendEmail(emails);
}
}
All Answers
You can achieve this functionality by using workflow rule.
Step1. Create a workflow rule
Step 2: Create Email Templates:
setup---->Communication Templates--->Email Templates
Here Patient and Appointment objects are in lookup relationship.
Step4: Once you done all steps then click done and Activate Workflow rule.
Same way you can create a one more workflow for the Patient object and create an Email Alert.
Hope this helps you!
Best Regards,
Jyothsna
My Requirement is to create an apex class and trigger to send an email.This should be done by coding part not admin part
Please check the below link similar to your requirement.
http://salesforce.stackexchange.com/questions/38947/sending-email-notification-using-trigger
Regards,
Jyothsna
public static void sendemailtoPatient(list<Appointment__c> appointments){
EmailTemplate et=[Select id from EmailTemplate where name='Appointment: New Customer Email'];
list<Messaging.SingleEmailMessage> emails = new list<Messaging.SingleEmailMessage>();
//To store patient Id
set<Id> setPatientId = new set<Id>();
if(appointments.size()> 0) {
for(Appointment__c iterator : appointments) {
if(iterator.Patient__c != null) {
setPatientId.add(iterator.Patient__c);
}
}
}
//fetch the patient records for whom an email needs to be sent
if(setPatientId.size()>0) {
list<Patient__c> Patients = [Select Id,Email__c from Patient__c where Id IN : setPatientId];
for(Patient__c pat : Patients){
if(pat.Email__c != null){
Messaging.SingleEmailMessage singleMail = new Messaging.SingleEmailMessage();
singleMail.toaddresses(pat.Email__c);
singleMail.setTemplateId(et.Id);
emails.add(singleMail);
}
}
}
Messaging.sendEmail(emails);
}
}