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

How to insert a FeedComment of Type ContentComment in testclass?



I am trying to insert a feedComment of contentcomment type on a feedpost in the follwing test method- 

when i run the test i get an error  saying "System.DmlException: Insert failed. First exception on row 0; first error: FIELD_INTEGRITY_EXCEPTION, You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.: []"


static testmethod void mytest(){
        Account Acc = new Account(Name = 'TestAccountBhushan',Phone = '040-754-7845');
        insert acc;  
        contentVersion cv = new contentVersion(
        pathonclient = 'My Document.docx',
        versionData = EncodingUtil.base64Decode('SampleImageFile')
        insert cv;   
        //Inserting  post on chatter
        FeedItem textFeed = new FeedItem(
                Body = 'This is a text post',
                Type = 'TextPost',
                ParentId =               
        insert textFeed;
        FeedComment fc = new FeedComment(
            feedItemId = textFeed.Id,
            relatedRecordId =,
            commentBody = 'Test Comment Body'
            //commentType = 'ContentComment'
        insert fc;
        system.debug('****** Comment******'+ fc);





Is this solved? I would try creating a user, then do a run as command. That might help.