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

  • How to write test class for Document object in Salesforce?

  • sushant

    Member
    January 3, 2017 at 1:59 pm

    Hi All,

    How to write test class for Document object?

    please give suggestions

    Thanks

  • 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.

     

Viewing 1 - 4 of 4 posts

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos