You need to sign in to do that
Don't have an account?
Document object in TestMethod
I'm trying to write a testmethod for an apex class that reads a file from Visual Force <apex:inputFile> and process the file.
I'm trying to add the test file to Document object and read the body of that document in my testMethod but that seems to be a problem as nothing was returned from the query even though the same query works fine in the class body. So testMethod can't access Document Object? Is that the right way to test a input file? Or I have to construct a Blob somehow on the fly? Or any other ways to let the test method read a file?
Thank you very much for any leads.
You can encode a test document as a base64 string, then hand that value to the blob object you've bound to your inputfile's body attribute.
(The encoded string is just the first paragraph encoded in base64).
All Answers
You can encode a test document as a base64 string, then hand that value to the blob object you've bound to your inputfile's body attribute.
(The encoded string is just the first paragraph encoded in base64).
You might not have @isTest(SeeAllData=true) set on your test method, as well. That would cause your query to fail as well.
I ended up constructing a blob in the testMethod.