Does anybody know of a way to order child records when accessed using a StandardController and displayed with an <apex:repeat> loop?

My guess is that it can't be done and I need an extension, custom controller or to use a related list but the question is simply regarding whether this is possible.


<!-- List these in order of created date -->
<apex:repeat value="{!Account.Contacts}" var="c">

1 Answer 1


I don't think there is anything like a setting or attribute to control that. There's an idea for <apex:repeat> with control over sort order.

If you absolutely cannot use an extension, you could resort back to JavaScript.

<apex:page standardController="Account" >
    <apex:outputText value="{!Account.Name}"/><br/>
    <div id="contacts"></div>

    <script type="text/javascript">
      var contacts = [];
      <apex:repeat value="{!Account.Contacts}" var="c">
              Name : "{!c.Name}",
              CreatedDate : new Date("{!c.CreatedDate}"),
              toString : function() { 
                  return this.CreatedDate + ', ' + this.Name; 

      contacts.sort(function(con1, con2) {
          var comp = con1.CreatedDate - con2.CreatedDate;
          if (comp > 0) {
             return 1;
          if (comp < 0) {
             return -1;
          return 0;
      // ...update the dom as desired...  
  • 2
    Accepted because as far as I know javascrpt is the only way to do this.
    – Matt Lacey
    Commented Mar 1, 2013 at 23:58

You must log in to answer this question.

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