function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Aidel BruckAidel 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 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 : 
      // 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)
      // Step 3: Set who the email is sent from
      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();
      // Step 5. Add your email to the master list
  // Step 6: Send all emails in the master list

public class TestNewFileAlert 

    public static testmethod void MyUnitTest()
    Account acct = new Account(Name='TEST_ACCT');
    insert acct;
    ContentVersion contentVersionobj = new ContentVersion();
    contentVersionobj.Title = '';            
    insert contentVersionobj;


Raj VakatiRaj Vakati
Try this
public class TestNewFileAlert 
    public static testmethod void MyUnitTest()
      //  test.startTest();
        Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
        UserRole r = [SELECT Id FROM UserRole WHERE Name='COO'];
        User futureUser = new User(firstname = 'Future', lastname = 'User',
                                   alias = 'future', defaultgroupnotificationfrequency = 'N',
                                   digestfrequency = 'N', email = '',
                                   emailencodingkey = 'UTF-8', languagelocalekey='en_US', 
                                   localesidkey='en_US', profileid = p.Id, 
                                   timezonesidkey = 'America/Los_Angeles',
                                   username = '',
                                   userpermissionsmarketinguser = false,
                                   userpermissionsofflineuser = false, userroleid = r.Id);
            Account acct = new Account(Name='TEST_ACCT');
            insert acct;
            ContentVersion contentVersion = new ContentVersion(
                Title = 'Penguins',
                PathOnClient = 'Penguins.jpg',
                VersionData = Blob.valueOf('Test Content'),
                IsMajorVersion = true
            insert contentVersion; 
            List<ContentDocument> documents = [SELECT Id, Title, LatestPublishedVersionId FROM ContentDocument];
            //create ContentDocumentLink  record 
            ContentDocumentLink cdl = New ContentDocumentLink();
            cdl.LinkedEntityId =;
            cdl.ContentDocumentId = documents[0].Id;
            cdl.shareType = 'V';
            insert cdl;
          //  test.stopTest();

Krishnaveni A 2Krishnaveni A 2
Hi ,

Krishnaveni A 2Krishnaveni A 2
I tried the above code, I didnt get any errors. Can u please explain in detail 
Raj VakatiRaj Vakati
You need to set the Create date in test class .. 

In your code you are refering the create date so ... 


i set like above and i set ruunAs users also .. its 100% code covergae 
Aidel BruckAidel Bruck
I ran the new test code and I am still getting the error!