You need to sign in to do that
Don't have an account?
Aidel Bruck
Insert Contentversion - The argument is null or invalid
This is my trigger And the test class
When running the test class I get 100% coverage yet the test fails and I get the following error:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ARGUMENT_TYPE, The argument is null or invalid.: []
Trigger
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');
// 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);
}
Test
@isTest
public class TestNewFileAlert
{
public static testmethod void MyUnitTest()
{
test.startTest();
Account acct = new Account(Name='TEST_ACCT');
insert acct;
ContentVersion contentVersionobj = new ContentVersion();
contentVersionobj.ContentURL='http://www.google.com/';
contentVersionobj.Title = 'Google.com';
insert contentVersionobj;
test.stopTest();
}
}
When running the test class I get 100% coverage yet the test fails and I get the following error:
System.DmlException: Insert failed. First exception on row 0; first error: INVALID_ARGUMENT_TYPE, The argument is null or invalid.: []
Trigger
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');
// 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);
}
Test
@isTest
public class TestNewFileAlert
{
public static testmethod void MyUnitTest()
{
test.startTest();
Account acct = new Account(Name='TEST_ACCT');
insert acct;
ContentVersion contentVersionobj = new ContentVersion();
contentVersionobj.ContentURL='http://www.google.com/';
contentVersionobj.Title = 'Google.com';
insert contentVersionobj;
test.stopTest();
}
}
In your code you are refering the create date so ...
Test.setCreatedDate(cdl.Id, DateTime.now());
i set like above and i set ruunAs users also .. its 100% code covergae