I've created a static resource XML file and uploaded it to my test org. My code coverage is around 41% and needs improvement due to there being numerous nodes in the XML file that need to be loaded into various custom objects. Much of the class that needs to be tested has the XML inline assigned to a string variable. What must be done to point that string variable to my static resource XML file instead?


You can query the static resource object during test methods and then get the body of the document and assign it to a string.

sr = [Select Body From StaticResource Where Name = '{DOCUMENT NAME}' LIMIT 1];

String s = sr.body.toString();
  • Do you have a link to sample code for this?
    – SidC
    Aug 27 '14 at 3:45
  • @SidC - Pretty simple. I have updated my answer
    – Eric
    Aug 27 '14 at 3:54

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.