So I have an SOQL query which returns an object with these fields:

|Product Name|Option|Category|

Category could be: A B

Options could be: 1 2 3

In my VisualForce page I would like to visualise that in this form:

Category A
Option 1

Product Name

Category B
Option 2

Product Name

Option 3

Product Name

That would be something like apex:repeat and then group by Category first, then by Option and finally display Name under that. The thing is that there could be multiple entries of Category A and B, while I would only like to display the Category name once and distribute Product Names accordingly. Situation with Option field is the same as with Category.

I would appreciate your help

1 Answer 1


You could create a Map, sth like this:

Map <String, List <String>> = productNameListByCategoryName = new Map <String, List <String>>();

then fill the map:

if (!productNameListByCategoryName .containsKey("YOUR_CATEGORY_NAME")) {
productNameListByCategoryName .put("YOUR_CATEGORY_NAME", new List <String> {"YOUR_PRODUCT_NAME"});

} else {
    productNameListByCategoryName .get("YOUR_CATEGORY_NAME").add("YOUR_PRODUCT_NAME");

then all what you have to do, is to iterate it. You can do the same with Option field.

You must log in to answer this question.

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