You need to sign in to do that
Don't have an account?
shekhar 46
send email on record update by apex
I want to send email to trainer dept and bcc to CEO, and want to share the data of training object in object
function readOnly(count){ }
You need to sign in to do that
Don't have an account?
I have tried the below code in my org.. its working fine. If this helps, Please mark it as best answer.
Thanks!!
All Answers
when you need to send an email to trainer. ?
Can you explain more about your requirement?
Thanks!!
Do you have the field called training dept user in training deal object?
Thanks!!
try with below code and modify the object api name as per your org.
If this helps, Please mark it as best answer.
Thanks!!
I want that Whenever mail is going to ceo , nobody should know , hence we want to keep in bcc.
try with below code.
If this helps, please mark it as best answer.
Thanks!!
trigger
trigger sendMail on Training_deal__c (before insert) {
SendMailTrigger.SendMailFunction(trigger.new);
}
class
public class SendMailTrigger {
public static void SendMailFunction( List<Messaging.SingleEmailMessage> VarMails ){
// Step 0: Create a master list to hold the emails we'll send
List<Messaging.SingleEmailMessage> mails = new List<Messaging.SingleEmailMessage>();
// Set list of people who should get the email
List<String> sendTo = new List<String>();
List<User> userlist = [select id,email from user where Profile.Name='Training dept'];
for(user u:userlist){
sendTo.add(u.email);
}
for (training_deal__c myContact : Trigger.new) {
// Step 1: Create a new Email
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
//Step 2: Set list of people who should get the email
mail.setToAddresses(sendTo);
// Step 3: Set who the email is sent from
mail.setSenderDisplayName('New Training Deal created');
// (Optional) Set list of people who should be Bcc'ed
List<String> BccTo = new List<String>();
ccTo.add('ggaikwad25794@gmail.com');
mail.setBccAddresses(BccTo);
// Step 4. Set email contents - you can use variables!
mail.setSubject('New Training Deal created');
String body = myContact.Name;
body += 'Training deal Record has been created';
mail.setHtmlBody(body);
// Step 5. Add your email to the master list
mails.add(mail);
}
}
// Step 6: Send all emails in the master list
Messaging.sendEmail(VarMails);
}
}
}
}
error
invalid character, invalid data type varmail
worng:
// Step 6: Send all emails in the master list
Messaging.sendEmail(VarMails);
correct:
// Step 6: Send all emails in the master list
Messaging.sendEmail(Mails);
Modify the code and check.
Thanks!!
error: variable does not exist :ccTo
Thanks!!
Let me know, still facing an issue.
If this helps, Please mark it as best answer.
Thanks!!
I have tried the below code in my org.. its working fine. If this helps, Please mark it as best answer.
Thanks!!
Thanks , now it is working fine. I was trying to write logic in apex class not is trigger, in that case was getting error.
this code is working directly.