Need help to write a test for the below trigger

trigger GFP_Update on ContentVersion (after insert) {

    if(trigger.new.get(0).Title == 'TestWebservice.csv'){


        //Make a @future method to update records
  • Please post the code of Test class you have tried so far. – Nachiket Deshpande Feb 22 '17 at 11:18

You should create an ContentNote or ContentVersion record in your test class and that would automatically create a ContentVersion record, hence, firing your ContentVersion trigger.

Sample code to create a ContentNote record is

// Insert a ContentNote record  
ContentNote cn = new ContentNote();
string body = 'Hello, World!';
cn = (ContentNote) TestFactory.createSObject(new ContentNote(Title='test note1',Content=Blob.valueOf(body.escapeHTML4())));

insert cn;
System.assert([Check the results you are expecting from your GPF_Parse CSV class here]);

and Viola!

P.S. TestFactory is a test data generation class and you can find tons of examples on the internet on that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.