You need to sign in to do that
Don't have an account?
Aidel Bruck
How to test this trigger on contentDocument
I have the following trigger I wrote for ContentDocument
I want to send an email alert to various users when a file is uploaded
This is the code and I would like to know how to test it
Also I need a way to get the account name the file is associated with
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(list of all addresses)
mail.setToAddresses(sendTo);
// Step 3: Set who the email is sent from
mail.setReplyTo('myaddress');
mail.setSenderDisplayName('Aidel Bruck');
// (Optional) Set list of people who should be CC'ed
//List<String> ccTo = new List<String>();
//ccTo.add('business@bankofnigeria.com');
//mail.setCcAddresses(ccTo);
// 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.sendEmail(mails);
}
Thanks!
I want to send an email alert to various users when a file is uploaded
This is the code and I would like to know how to test it
Also I need a way to get the account name the file is associated with
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(list of all addresses)
mail.setToAddresses(sendTo);
// Step 3: Set who the email is sent from
mail.setReplyTo('myaddress');
mail.setSenderDisplayName('Aidel Bruck');
// (Optional) Set list of people who should be CC'ed
//List<String> ccTo = new List<String>();
//ccTo.add('business@bankofnigeria.com');
//mail.setCcAddresses(ccTo);
// 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.sendEmail(mails);
}
Thanks!
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ARGUMENT_TYPE, The argument is null or invalid.: []
@isTest
02public class ContentDocument_Test{
03 public static testmethod void MyUnitTest(){
04 Account acct = new Account(Name='TEST_ACCT');
05 insert acct;
06
07 ContentVersion contentVersion = new ContentVersion(
08 Title = 'Penguins',
09 PathOnClient = 'Penguins.jpg',
10 VersionData = Blob.valueOf('Test Content'),
11 IsMajorVersion = true
12 );
13 insert contentVersion;