You need to sign in to do that
Don't have an account?
Aidel Bruck
Email not sending from trigger
Hello all,
I am really having trouble for the past week and have not gotten any solutions thus far.
I wrote a trigger to send an email every time a file is uploaded,
It has 100% coverage and from the log it is apparent that the email is sent out
The setting for deliveribilty is set to all emails, and I tested deliveribility with success.
And yet I am not getting the email
Can anybody help me figure out why??
This is the code
trigger NewFileAlert on ContentDocument (after insert)
{
// Step 0: Create a master list to hold the emails we'll send
List<Messaging.SingleEmailMessage> mails =
new List<Messaging.SingleEmailMessage>();
for (ContentDocument newDoc : 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
List<String> sendTo = new List<String>();
sendTo.add('test@gmail.com');
....
mail.setToAddresses(sendTo);
// Step 3: Set who the email is sent from
mail.setReplyTo('me@gmail.com');
mail.setSenderDisplayName('Aidel Bruck');
// Step 4. Set email contents - you can use variables!
mail.setSubject('New Document Added');
String body = 'Please note: A new document has been added/n ';
body += 'File name: '+ newdoc.title+'/n' ;
body += 'Created By: '+ newdoc.createdbyid+ '/n';
body += 'Created Date: '+ newdoc.CreatedDate+ '/n';
body += 'link to file: '+ System.URL.getSalesforceBaseUrl().getHost()+newdoc.id;
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.SendEmailResult[] results = Messaging.sendEmail(mails);
if (results[0].success) {
System.debug('The email was sent successfully.');
} else {
System.debug('The email failed to send: '
+ results[0].errors[0].message);
}
}
Thanks!
I am really having trouble for the past week and have not gotten any solutions thus far.
I wrote a trigger to send an email every time a file is uploaded,
It has 100% coverage and from the log it is apparent that the email is sent out
The setting for deliveribilty is set to all emails, and I tested deliveribility with success.
And yet I am not getting the email
Can anybody help me figure out why??
This is the code
trigger NewFileAlert on ContentDocument (after insert)
{
// Step 0: Create a master list to hold the emails we'll send
List<Messaging.SingleEmailMessage> mails =
new List<Messaging.SingleEmailMessage>();
for (ContentDocument newDoc : 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
List<String> sendTo = new List<String>();
sendTo.add('test@gmail.com');
....
mail.setToAddresses(sendTo);
// Step 3: Set who the email is sent from
mail.setReplyTo('me@gmail.com');
mail.setSenderDisplayName('Aidel Bruck');
// Step 4. Set email contents - you can use variables!
mail.setSubject('New Document Added');
String body = 'Please note: A new document has been added/n ';
body += 'File name: '+ newdoc.title+'/n' ;
body += 'Created By: '+ newdoc.createdbyid+ '/n';
body += 'Created Date: '+ newdoc.CreatedDate+ '/n';
body += 'link to file: '+ System.URL.getSalesforceBaseUrl().getHost()+newdoc.id;
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.SendEmailResult[] results = Messaging.sendEmail(mails);
if (results[0].success) {
System.debug('The email was sent successfully.');
} else {
System.debug('The email failed to send: '
+ results[0].errors[0].message);
}
}
Thanks!
I Tested your code. its works well. and i got email when i create new Account. the only chnage i made is BODY part
Below is the email which i got..
kinldy check the body part which you added to this email content. hope this will give you some idea to debug.
Thanks
karthik
I changed the body just like you did and I still did not get the email.
Is there a problem to create an email alert through a trigger on content document?
Please once check the email Deliverability of your SF org. Maybe this will the reason that you can't get the mail.
Find from "Quick Find Box >> Deliverability (Type)".
Change the "Access Level" from "System Email Only" to "All Email".
Yes, you are right. i checked the same. trigger event will not work on ContentDocument. its based on ContentVersion, kinldy do the following.
Delete Trigger in ContentDocument. Create same trigger in ContentVersion. its should work. then try to upload file. your trigger will work
I got a emai alert,
for more information kinldy refer below thread.
https://salesforce.stackexchange.com/questions/76015/trigger-on-contentdocument-not-working hope it solve your isssue.
Thanks
karthik