You need to sign in to do that
Don't have an account?
dotNetkow
Unit testing with Static Resources
I have a method that I need to unit test which retrieves a Static Resource object based on the name of the file passed to the method. In the unit test, I'd like to insert a new Static Resource, like so:
Blob b = Blob.valueOf('file contents here'); StaticResource resource = new StaticResource(Body=b,Name='testFileName'); insert resource; // call method to test with newly created Static Resource string result = methodToTest('testFileName');
However, it fails when trying to insert the static resource. How else can I insert it? Thanks.
Static resources aren't available from apex I'm afraid - they are part of the metadata api.
All Answers
Static resources aren't available from apex I'm afraid - they are part of the metadata api.
Ok, so there is absolutely no way to insert/create static resources via apex then?
I'm afraid not. I've been trying to access them that way for a while now but haven't found a way though. They are only available to visualforce pages or the metadata api (force.com ide for example).
These days, you can access static resources from Apex like so: