I am doing a SOQL query and return all cases similar to this:

List cases = [Select Id, Name, State from Case];

I have 4 repeaters in a visualforce page and I want to bind each repeater to a subset of the cases list based on status. Is there an Apex version of the way you would do this in .NET with a LINQ select type filter or do I have to either a) iterate through the cases list creating a new list for each status or b) do a separate SOQL query for each case status and bind them all separately. I was hoping to avoid b since that would be more SOQL limits used. Any help or advice would be appreciated I figured someone knows the right way to do this.

I did find one very similar question and the answer describes what I am looking for but I don't understand the pseudo code used in the answer: similar question and answer



1 Answer 1


There is no equivalent of LINQ in Apex (how I wish there was), so you're right your two options are:

  • One big query, which you then "filter" in Apex code. I'd recommend using a for loop to iterate over every case and storing them in a Map<String, List<Case>> keyed by Status which you can then expose to your Visualforce page from your controller.

  • Multiple smaller queries with the results for each stored in a separate List<Case> exposed to your controller.

The first method is the preferred one, since as you rightly it reduces the number of SOQL queries that need to be performed.

You can then access the map in your apex:repeat like this:

<apex:repeat value="{!yourmap['key']}" var="listvalue">

You must log in to answer this question.

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