12

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?

3
  • Which subquery fields? And how are you referencing them? Please post the code that's giving you the error (plus a brief explanation of what you're doing). Sep 25, 2013 at 14:08
  • What are you doing with the subquery fields? Are you using them as an input parameter to something else? Is so, does the controller expect the input parameter to be a string and not a Number (Decimal, Integer, ...) Sep 25, 2013 at 14:10
  • error occurs on this line: <apex:column value="{!obj.Investment_Programs__r[0].Status__c}"/>
    – paul
    Sep 25, 2013 at 14:13

3 Answers 3

1

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>
0

Since the issue lies here:

<apex:column value="{!obj.Investment_Programs__r[0].Status__c}"/>

And this is what you're doing:

<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}"/>  <------ HERE
        <apex:column value="{!obj.Probability__c}"/>
    </apex:pageBLockTable>
</apex:repeat>

Notice that in the error line, you are referencing the Investment_Programs__r[0] like a list while you are referencing every other parameter as a field (like obj.Name).

I think this is causing the error.

1
  • i guess the question is how do i access the data from the subquery in this scenario.
    – paul
    Sep 25, 2013 at 14:24
0

I don't think you can use apex:column to address a specific element of the subquery using the value attribute. Can you do this instead:

<apex:column headerValue="Investment Program Status"/>
    {!obj.Investment_Programs__r[0].Status__c}
</apex:column>

In addition, unrelated to your pageBlockTable problem, I think you have a problem here:

    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);
    }

You're leaving out the first record when you create the list. A simple solution would be to create the new list as new List<Site__c>{ r }.

I prefer this route, which becomes more attractive if you need to use the list for more than one action:

List<Site__c> siteList = mapFYToList.get(r.Investment_Programs__r[0].Launch_FY__c);
if (siteList == null)
{
    siteList = new List<Site__c>();
    mapFyToList.put(r.Investment_Programs__r[0].Launch_FY__c, siteList);
}
siteList.add( r);

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .