[SalesForce] Incorrect parameter type for subscript. Expected Text, received Number

this is a follow on issue from a previous question, though id post as seperate question as that specific issue had been answered:

List – break into different PageBlockTables

Essentially using a map to generate a number of pageBlockTables, the data is based on a query with a couple of subqueries, all works when referencing the many queries fields, however when i reference the subquery fields i get error 'Incorrect parameter type for subscript. Expected Text, received Number'

<apex:repeat value="{!keys}" var="fy">
      <apex:pageBlockTable value="{!mapFYToList[fy]}" var="obj">
        <apex:column value="{!obj.Name}"/>
        <apex:column value="{!obj.Postcode__c}"/>
        <apex:column value="{!obj.Investment_Programs__r[0].Status__c}"/>
        <apex:column value="{!obj.Probability__c}"/>
      </apex:pageBLockTable>
    </apex:repeat>

controller code

 public map<String, List<Site__c>> mapFYToList {get;private set;}

public SDGProgrammeController()
{   
     mapFYToList = new map<String, List<Site__c>>();

     for(Site__c r : [Select StoreNo__c, Probability__c, Name, JS_Region__c,JS_Zone__c, Address__c, Postcode__c, 
                                        (Select MeetingDate__c,RecordType.name,Total_Sales_Area_Uplift__c, TU_Sales_Area_Uplift__c, TUSalesAreaPre__c, 
                                            TUSalesAreaPost__c, SalesAreaPreExcCO__c, SalesAreaPostExcCO__c, NonFoodSalesAreaUplift__c, NonFoodSalesAreaPre__c, 
                                            NonFoodSalesAreaPost__c, GMSalesAreaUplift__c, GMSalesAreaPre__c, GMSalesAreaPost__c, FoodSalesAreaUplift__c, 
                                            FoodSalesAreaPre__c, FoodSalesAreaPost__c 
                                        From Financial__r 
                                        where MeetingDate__c != null and Recordtype.Name IN('CCM','CCM Update','IB')
                                        order by MeetingDate__c desc
                                        limit 1),
                                     (Select Launch_date__c,Start_On_Site__c, Status__c,Store__c,ProjectName__c,Investment_Type__c,ProjectManager__c, 
                                        MainContractor__c,RetailHandover__c,Closure__c,Launch_FY__c,Launch_Period__c, Launch_Quarter__c 
                                     FROM Investment_Programs__r 
                                     WHERE Status__c In('Live','Feasibility','Completed') and RecordType.Name ='New Store' )
                                    FROM Site__c where Recordtype.name = 'Supermarket' and Probability__c IN('Open','Certain','Possible','Probable')
                                        AND Id IN(Select Site__c from Financial__c WHERE MeetingDate__c != null and Recordtype.Name IN('CCM','CCM Update','IB'))
                                        AND Id IN(Select Site__c from InvestmentProgram__c WHERE Status__c In('Live','Feasibility','Completed') and RecordType.Name ='New Store') 
                                        order by Launch_Date__c asc limit 999])
    {
        if(mapFYToList.get(r.Investment_Programs__r[0].Launch_FY__c) == null)
        {
            mapFyToList.put(r.Investment_Programs__r[0].Launch_FY__c, new List<Site__c>());
        }
        else
        {
            mapFyToList.get(r.Investment_Programs__r[0].Launch_FY__c).add(r);
        }
        system.debug(mapFyToList);
    }


}
    public List<String> getKeys()
    {
        List<String> keys = new List<String>();
        keys.AddAll(mapFYToList.KeySet());
        keys.sort();
        return keys;

    }

}

the notation works fine if i just use it with a standard PBT populated with a list. Any ideas?

Best Answer

In your case I would make a wrapper class that holds the info you want. Store the wrapper in the map, and then reference the wrapper.

public map<String, List<WrapperClass>> mapFYToList {get;private set;}

public SDGProgrammeController()
{   
 mapFYToList = new map<String, List<WrapperClass>>();

 for(Site__c r : [SELECT StoreNo__c, Probability__c, Name, JS_Region__c,JS_Zone__c, Address__c, Postcode__c, 
                            (SELECT MeetingDate__c,RecordType.name,Total_Sales_Area_Uplift__c, TU_Sales_Area_Uplift__c, TUSalesAreaPre__c, 
                                    TUSalesAreaPost__c, SalesAreaPreExcCO__c, SalesAreaPostExcCO__c, NonFoodSalesAreaUplift__c, NonFoodSalesAreaPre__c, 
                                    NonFoodSalesAreaPost__c, GMSalesAreaUplift__c, GMSalesAreaPre__c, GMSalesAreaPost__c, FoodSalesAreaUplift__c, 
                                    FoodSalesAreaPre__c, FoodSalesAreaPost__c 
                                FROM Financial__r 
                                WHERE MeetingDate__c != null AND Recordtype.Name IN('CCM','CCM Update','IB')
                                ORDER BY MeetingDate__c desc
                                LIMIT 1),
                            (SELECT Launch_date__c,Start_On_Site__c, Status__c,Store__c,ProjectName__c,Investment_Type__c,ProjectManager__c, 
                                    MainContractor__c,RetailHandover__c,Closure__c,Launch_FY__c,Launch_Period__c, Launch_Quarter__c 
                                 FROM Investment_Programs__r 
                                 WHERE Status__c IN('Live','Feasibility','Completed') AND RecordType.Name ='New Store' )
                    FROM Site__c 
                    WHERE Recordtype.name = 'Supermarket' AND Probability__c IN('Open','Certain','Possible','Probable')
                        AND Id IN(SELECT Site__c FROM Financial__c WHERE MeetingDate__c != null AND Recordtype.Name IN('CCM','CCM Update','IB'))
                        AND Id IN(SELECT Site__c FROM InvestmentProgram__c WHERE Status__c IN('Live','Feasibility','Completed') AND RecordType.Name ='New Store') 
                        ORDER BY Launch_Date__c asc LIMIT 999])
{
    if(mapFYToList.get(r.Investment_Programs__r[0].Launch_FY__c) == null)
    {
        mapFyToList.put(r.Investment_Programs__r[0].Launch_FY__c, new List<WrapperClass>{new WrapperClass(r)};
    }
    else
    {
        mapFyToList.get(r.Investment_Programs__r[0].Launch_FY__c).add(new WrapperClass(r));
    }
    system.debug(mapFyToList);
}


}
public List<String> getKeys()
{
    List<String> keys = new List<String>();
    keys.AddAll(mapFYToList.KeySet());
    keys.sort();
    return keys;
}

public class WrapperClass
{
    String name {get; set;}
    String postCode {get; set;}
    Stirng status {get; set;}
    Integer probability {get; set;}

    public WrapperClass(Site__c site)
    {
        name = site.Name;
        postCode = site.Postcode__c;
        status = site.Investment_Programs__r[0].Status__c;
        probability = site.Probability__c;
    }
}
}

And then in your VF Page

<apex:repeat value="{!keys}" var="fy">
  <apex:pageBlockTable value="{!mapFYToList[fy]}" var="obj">
    <apex:column value="{!obj.name}"/>
    <apex:column value="{!obj.postCode}"/>
    <apex:column value="{!obj.status}"/>
    <apex:column value="{!obj.probability}"/>
  </apex:pageBLockTable>
</apex:repeat>
Related Topic