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
Jerrod Knapp 11Jerrod Knapp 11 

test class for contentversion object

I am writing a test class for a contentversion trigger.  VersionData is a required field and is a base64.  How do I represent a base64 in my test class?  When I try to put in a value I get an error similar to this:   "Illegal assignment from String to Blob"
Amit Chaudhary 8Amit Chaudhary 8
Hi Jerrod Knapp 11,

I will recommend you to start using trailhead to learn about test classes
1) https://trailhead.salesforce.com/modules/apex_testing

Also please check below post
1) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_qs_test.htm
2) https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_testing_example.htm

Pleasse check below post sample test class
1) http://amitsalesforce.blogspot.com/2015/06/best-practice-for-test-classes-sample.html

You write a test class for this the same way that you would any other:

- Set up some data for the Trigger to access (ContentVersion )
- Instantiate the Trigger- ContentVersion record
- Execute a method/methods
- Verify the behaviour with asserts.

Sample test class to start
@istest
private class ContentVersionTest {

    static testMethod void testProjectName(){
        
        ContentVersion cv = new ContentVersion();
			cv.title='Test title';
			cv.VersionData=blob.valueof('New Bitmap Image.bmp');
			//cv.PathOnClient ='/abc.txt';
			//cv.origin  ='H';
			// Add all required field
			
			//Blob bodyBlob=Blob.valueOf('Unit Test ContentVersion Body'); 
            //cv.VersionData=bodyBlob; 
			
        insert cv;
		
		update cv;
		
	}
}

Let us know if this will help you