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
BellaBella 

Multiple Type Object Custom List

How do I display a list with objects of different types. I have to have show a list of Sales Orders and for each sales order a list of Sales Order Item objects that are related to the sales order through a relationship list. I'd like to be able to display it in such a fassion:

 

- Sales order 1

* Item 1

* Item 2

- Sales order 2

* Item 1

* Item 2

 

And so on. Right now I can get a list of sales orders but how do I then show the items related to each one? Any ideas? Any good examples?
Message Edited by Bella on 03-12-2010 01:20 PM
Best Answer chosen by Admin (Salesforce Developers) 
XactiumBenXactiumBen

So what you would have to do in the component is to loop around all of your SLC records (which you are currently doing with the pageBlockTable) then have another pageBlockTable/repeat tag for the child records:

 

<apex:component controller="findSLCFamily" access="global"> <apex:pageBlock > <apex:pageBlockTable value="{!SLCFamily}" var="s_slc"> <apex:column value="{!s_slc.License_Order__c}"/> <apex:column > <apex:facet name="header" ><b>License Code</b></apex:facet> <apex:outputLink value="/{!s_slc.id}" > {!s_slc.Name} </apex:outputLink> </apex:column> <apex:column > <apex:facet name="header" ><b>Product</b></apex:facet> <apex:outputField value="{!s_slc.Product__c}"/> </apex:column> <apex:column value="{!s_slc.Devices__c}"/> <apex:column value="{!s_slc.SUP_End_Date__c}"/> <apex:column value="{!s_slc.Original_SLC__c}"/> <apex:column> <apex:repeat value="{!s_slc.Sales_Order_Items__r}" var="item"> {!item.Product__c}<br /> </apex:repeat> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:component>

 

I've highlighted in red my changes.  I've simply created a new column then used a repeat tag to display the sales order items' product on seperate lines.  I don't see why you couldn't change this to include another pageBlocktable within that column tag.

All Answers

imuinoimuino

You could use a map to relate both lists, in fact it will be like one list with other lists inside.

A map takes a key, lets say Sales 1 and you can relate it to a list of items

 

Map<String, List<String>>{get; set;}

Where the first String is the key and the second the list of items.

 

Let me know if it helps you so i can guide thru on how to show the map on your visualforce page

BellaBella

That's a really good idea. Can it all be done within the same controller? Right now I have the one for the upper level items that just collects a list of them. The problem (if it's a problem) that I found when looking at the relationship is that the upper level items are not aware of lower level items. That is, the items know which sales order they belong to via lookup field but the sales orders don't know which items they have aside from the related list we see vissually. So I guess I'd also need a map<id, object> for each and then match the ids of the sales orders to the lookup field in the items.

imuinoimuino
It would help to see some of your code to understand a little more
BellaBella

Each SLC has a related list of Sales Order Item objects. Each Sales Order Item is aware of which SLC it belongs to through a lookup field called AddonSLC__c. What I'd like to see is a list of SLCs (given by the code above) and for each SLC, slightly indented, a list of Sales Order Items who point to that SLC in their  AddonSLC__c field.

XactiumBenXactiumBen

If they are related you should just be able to use a single SOQL query to get what you want:

 

public class findSLCFamily { private final List<SLC__c> slcs; private final SLC__c currentSLC; public findSLCFamily() { slcs = [Select Id, (Select Name From License_Orders__r) from SLC__c]; } public List<SLC__c> getSLCFamily() { return slcs; } }

The child query is denoted by the normal brackets.  If you wanted to access these child records you just use slcs[0].License_Orders__r, which returns a list of License Order records related to slcs[0] record.  License_Orders__r is the name of the child relationship - you should be able to get this by clicking on the lookup field relating these objects under setup.

 

Hope that makes sense.

BellaBella

That's an idea. I'm a little fuzzy on how to put that into the component though. If I have the following in the controller:

 

 

slcs = [Select (Select Id, Product__c, Product_Family__c From Sales_Order_Items__r), Name, License_Order__c, Product__c, Devices__c, SUP_End_Date__c, Original_SLC__c from SLC__c where Original_SLC__c = :currentSLC.Original_SLC__c order by License_Order__c];

 

I'd have to add "s_slc[0].Sales_Order_Items__r" to the component above, but where exactly would it go? Is it a new block? I'm really new to this ^^;;

 


 

Message Edited by Bella on 03-16-2010 08:56 AM
XactiumBenXactiumBen

So what you would have to do in the component is to loop around all of your SLC records (which you are currently doing with the pageBlockTable) then have another pageBlockTable/repeat tag for the child records:

 

<apex:component controller="findSLCFamily" access="global"> <apex:pageBlock > <apex:pageBlockTable value="{!SLCFamily}" var="s_slc"> <apex:column value="{!s_slc.License_Order__c}"/> <apex:column > <apex:facet name="header" ><b>License Code</b></apex:facet> <apex:outputLink value="/{!s_slc.id}" > {!s_slc.Name} </apex:outputLink> </apex:column> <apex:column > <apex:facet name="header" ><b>Product</b></apex:facet> <apex:outputField value="{!s_slc.Product__c}"/> </apex:column> <apex:column value="{!s_slc.Devices__c}"/> <apex:column value="{!s_slc.SUP_End_Date__c}"/> <apex:column value="{!s_slc.Original_SLC__c}"/> <apex:column> <apex:repeat value="{!s_slc.Sales_Order_Items__r}" var="item"> {!item.Product__c}<br /> </apex:repeat> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:component>

 

I've highlighted in red my changes.  I've simply created a new column then used a repeat tag to display the sales order items' product on seperate lines.  I don't see why you couldn't change this to include another pageBlocktable within that column tag.

This was selected as the best answer
BellaBella
Actually I just tried it and it looks about right. I need to think some more about what information I need to extract but I can see the Sales Order Item objects which is great! Thank you so much!
Jon Mountjoy_Jon Mountjoy_
Bella, please mark a post in this thread as "Solution" - it sounds like you have one!  Thanks.