1

What order does the VisualForce Repeater return information in?

I'm making a Visualforce email where the aim is to retrieve the most current record of information in a related object to the one which the email is related to, namely Account and the Contracts linked to account.

I only want it to send the most recent Contract record data as part of this email.

Something like the below is currently being used to do this, I just want to guarantee that it will always return what I want:

 <table border="0" >
   <col width="900"/>
   <caption>Deal Overview</caption>
   <tr>
    <th>Contract Term (months)</th>
  </tr>
  <tr>
    <apex:repeat var="ctrtx" value="{!relatedTo.Contracts}" rows="1">          
    <td>{!ctrtx.ContractTerm}</td>
    </apex:repeat> 
  </tr>
</table>

1 Answer 1

0

If the list of records is coming from the standard controller, you cannot rely on the order of the results. If the list is generated from a query, it will be indeterminate unless an order by clause was specified.

The problem isn't the iterator, which is guaranteed to output results in the order which they appear in the array, but rather the underlying query, which may be ordered in any arbitrary order by the query optimizer in the absence of an order by clause.

3
  • Standard Controller. I wonder if I can change the entire thing around to work from Contracts. So it sources information from Account. I don't know if I can pull in Contact information this way though. I chose Account as the host for this as it was one step from Contract and Contacts.
    – 44f
    Commented Dec 12, 2014 at 17:21
  • Use account if you need all the contacts from the account, otherwise you can use the lookup fields found on the contract object to pull in contact information. If you get too much more complicated, you'll probably need an actual controller.
    – sfdcfox
    Commented Dec 12, 2014 at 17:48
  • Got far too much stuff that needs to come through from the Contracts page. I'm going to have to make a controller it seems. This is where I start to get sketchy. Ok, I'll leave this here as answered as far as I am concerned, thanks for the help.
    – 44f
    Commented Dec 12, 2014 at 21:21

You must log in to answer this question.

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