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
jdogsailingjdogsailing 

DataTable Noob Question

I'm trying to build a page with a datatable that can display multiple values derived from, but not stored in an SObject. All the examples show the controller extension method returning SObject lists (e.g. Account[], which works just fine), but I want to display some computed values that are not stored in the SObject (e.g. the number of Contacts in the Account).

 

Normally, I would just declare a bean with the SObject fields plus the computed fields and have the controller return that, but I do not see a way to do this in force.com. All SObjects are persistent and I do not wish to create table fields to store these computed values.

 

The only way I can think of to proceed is by having the controller extension method return a List<Map<String, String>> instead of SObject[]. I have coded the controller method and it is happy, but when I try to invoke the get() method on the map my page will no longer compile (save error: unknown function obj.get. Check spelling). Here's a fragment...

 

    public List<Map<String, String>> getSummary(){...}

 

             <apex:datatable value="{!summary}" var="obj" styleClass="list">
                <apex:column>
                    <apex:facet name="header">Account Name</apex:facet>
                    <apex:outputText>
                        <a href="Detail?id={!obj.get('id')}">{!obj.get('name')}</a>
                    </apex:outputText>
                </apex:column>
                <apex:column>
                    <apex:facet name="header">#Contacts</apex:facet>
                    <apex:outputText>{!obj.get('contacts')}</apex:outputText>
                </apex:column>

 

Can someone give me a hint about how to proceed?

Best Answer chosen by Admin (Salesforce Developers) 
JimRaeJimRae
Use a custom class to combine your derived values and your sObject data together. Look for references to a "Wrapper class", that is what you want to do.  You basically will create the custom class, and then a list of the custom objects to store the data.  populate the list with your custom objects, then access the list for your datatable.

All Answers

JimRaeJimRae
Use a custom class to combine your derived values and your sObject data together. Look for references to a "Wrapper class", that is what you want to do.  You basically will create the custom class, and then a list of the custom objects to store the data.  populate the list with your custom objects, then access the list for your datatable.
This was selected as the best answer
jdogsailingjdogsailing

Thanks Jim, searching the help documents yielded no hits but the discussion boards had many citations that got me through.

 

Jeff