function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sid ChildersSid Childers 

Error Initial Term of Field Expression must be a concrete SObject.List<StaticResource>

I've written the following in a test class attempting to achieve adequate code coverage by parsing XML nodes into various field values.  I want to reference the static resource XML file in test classes instead of entering the actual XML and assigning it to a XMLStr.  However, I am receiving the error stated above.
List<StaticResource> ifx;
		ifx = [Select Body from StaticResource where Name = '{Direct8_8_Decision}' LIMIT 1];
        string XMLStr = ifx.body.ToString();
        Dom.Document xmlDoc = new Dom.Document();
        xmlDoc.load(xmlStr);
        IFXLoadXML.IFXMain ifxObj = new IFXLoadXML.IFXMain(xmlDoc.getRootElement());
        System.assertNotEquals(null, xmlDoc);

What must be fixed in order for the Static Resource to be loaded into the test class, XML nodes evaluated etc.?
Best Answer chosen by Sid Childers
AshwaniAshwani
Modify the query as:

List<StaticResource> ifx;
		ifx = [Select Body from StaticResource where Name = '{Direct8_8_Decision}' LIMIT 1];
       if(ifx.size()>0)
       {
         string XMLStr = ifx[0].body.ToString();
         Dom.Document xmlDoc = new Dom.Document();
         xmlDoc.load(xmlStr);
         IFXLoadXML.IFXMain ifxObj = new IFXLoadXML.IFXMain(xmlDoc.getRootElement());
         System.assertNotEquals(null, xmlDoc);
      }

Your query is not returning any record.

All Answers

Bhawani SharmaBhawani Sharma
Shouldn't it:
string XMLStr = ifx[0].body.ToString();
AshwaniAshwani
Try this:

List<StaticResource> ifx;
		ifx = [Select Body from StaticResource where Name = '{Direct8_8_Decision}' LIMIT 1];
        string XMLStr = ifx[0].body.ToString();
        Dom.Document xmlDoc = new Dom.Document();
        xmlDoc.load(xmlStr);
        IFXLoadXML.IFXMain ifxObj = new IFXLoadXML.IFXMain(xmlDoc.getRootElement());
        System.assertNotEquals(null, xmlDoc);

You have list on sobject not the sObject alone.
Sid ChildersSid Childers
Thanks to both of your for your suggestion.  I now receive System.ListException: List Index Out of Bounds: 0
Bhawani SharmaBhawani Sharma
Do you have any Static Resource with name {Direct8_8_Decision}? Regards, Bhavi Sharma Certified Salesforce Consultant bhavi@simplyforce.com/bhawani.sh.sharma@gmail.com +91-9928130589 LinkedIn | Twitter | Blog | Community www.simplyforce.com
AshwaniAshwani
Modify the query as:

List<StaticResource> ifx;
		ifx = [Select Body from StaticResource where Name = '{Direct8_8_Decision}' LIMIT 1];
       if(ifx.size()>0)
       {
         string XMLStr = ifx[0].body.ToString();
         Dom.Document xmlDoc = new Dom.Document();
         xmlDoc.load(xmlStr);
         IFXLoadXML.IFXMain ifxObj = new IFXLoadXML.IFXMain(xmlDoc.getRootElement());
         System.assertNotEquals(null, xmlDoc);
      }

Your query is not returning any record.
This was selected as the best answer
Bhawani SharmaBhawani Sharma
Also, as you want to process exisitng data, you will have to use SeeAllData = true.
Sid ChildersSid Childers
Thanks!  The error is now resolved.

Bhawani SharmaBhawani Sharma
Please mark the question resolved. Regards, Bhavi Sharma Certified Salesforce Consultant bhavi@simplyforce.com/bhawani.sh.sharma@gmail.com +91-9928130589 LinkedIn | Twitter | Blog | Community www.simplyforce.com
Bhawani SharmaBhawani Sharma
Your code coverage is good ? Looks like it was data dependency.
Sid ChildersSid Childers
@Bhawan1 Code coverage is still at 42%.  
Bhawani SharmaBhawani Sharma
Make sure you have static resource in org and seeAllData.