Activity Forums Salesforce® Discussions How to write test class for Document object in Salesforce?

  • PRANAV

    Member
    January 3, 2017 at 6:01 pm

    Hi Sushant,

    Document documentObj;

    documentObj = new Document();
    documentObj.Body = Blob.valueOf('Some Document Text');
    documentObj.ContentType = 'application/pdf';
    documentObj.DeveloperName = 'my_document';
    documentObj.IsPublic = true;
    documentObj.Name = 'My Document';
    documentObj.FolderId = [select id from folder where name = 'My Test Docs'].id;
    insert documentObj;

    Use this snippet of code under your test class, this may help you.

    Thanks

  • sushant

    Member
    January 4, 2017 at 1:30 pm

    Thanks

  • Priyanka Dhanorkar

    Member
    September 24, 2018 at 2:33 pm

    This does not work for me.

    It says "A value cannot be stored to FolderId in type Document" when i try to assign value of folder id in the document object.

     

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos