I am trying to write a test class to test an Apex class that uses FeedItem object. The Apex class checks if the FeedItem record has a BestCommentId and does some actions. A snippet of the test data that I am creating is as follows -

FeedItem fi = new FeedItem(Title = 'Feed Title',ParentId = parentId,Type = 'QuestionPost');
insert fi;
FeedComment fc = new FeedComment(CommentBody = 'Comment Body',FeedItemId = fi.Id);
insert fc;
fi.BestCommentId = fc.Id;
update fi;

I get an exception on fi.BestCommentId = fc.Id line that says Field is not writeable: FeedItem.BestCommentId. Is there a way to do this? Especially without using seeAllData=true.

  • 1
    The field itself is not updateable and thus I don't think you can really update it from test class either. There's an idea to allow the ability to set this field.
    – Jayant Das
    Apr 8 '19 at 13:05
  • @JayantDas - Thank you. I've upvoted the idea.
    – yeselkay
    Apr 9 '19 at 4:37

Your Answer

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

Browse other questions tagged or ask your own question.