So I have some apex code that is query some Content Workspaces, Documents and Versions. As far as I can tell these are ready only in Apex.

Error: Field is not writeable: ContentDocument.Title

So how do I write test methods that can populate these items?

  • ContentDocument record automatically gets created when you create a ContentVersion record, you don't need to specifically need to create it separately. You can always query and use the ContentDocumentId field of ContentVersion record created ...
    – VarunC
    Jan 1 '14 at 6:46
  • Yes I realizes that... I guess I am limited to just using real data for testing then.
    – NSjonas
    Jan 2 '14 at 2:49

You are correct. You will have to rely on existing metadata to complete your tests. You can still create documents and put them existing library's.

One thing I did in my tests for a similar implementation is to ensure that after every SQL I check to see if the list was empty. If it was I set a variable to a useful error message.

Then I system.assertEquals('false',varName);

That way if the list was not empty it passed and if it was empty I could at least present a useful error when the user looked as the reason it failed without having to review code or use the developer console.

Sometimes seeing

Expected: false, Actual: The record type 'Public Library' does not exist. Please create it to continue the test

is all the end user needs to resolved the issue. Sometime it is all the developer needs when the time lapse between writing the code and troubleshooting is lengthy.

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.