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
DanielJimenezDanielJimenez 

Comments out of order.

Hi, 

 

I'm creating a simple visual force email template for my case alerts. I'm using apex:repeat to loop over relatedTo.CaseComments and display them in a simple table. However the comments are out of order, for example they display in the order below...

 

Fri Oct 16 05:00:00 GMT 2009

Mon Oct 19 05:00:00 GMT 2009

Tue Jun 08 15:35:21 GMT 2010

Mon Oct 19 05:00:00 GMT 2009

 

Is there a simple solution for this? Besides using a controller? I'd think they'd be in order in the database.

 

Thanks in advance!

Daniel

Best Answer chosen by Admin (Salesforce Developers) 
SteveBowerSteveBower

I'm gathering that you're not writing your own controller, but just using the standard controller.  If that's the case, I don't think you have any control over this.  -S

All Answers

SurekaSureka

Hi,

 

If you are using a query to display the case comments, then try using "Order By"  in the Query.

 

Thanks

SteveBowerSteveBower

I'm gathering that you're not writing your own controller, but just using the standard controller.  If that's the case, I don't think you have any control over this.  -S

This was selected as the best answer
DanielJimenezDanielJimenez
That's right I'm using the StandardController. I'm wondering why they are out of order, I assumed they would be in the order entered. Is there an easy way to run a query from VisualForce without having to create a controller? Thanks for the answers guys, I'm learning but I'm still a VF/Apex newbie. Daniel
SteveBowerSteveBower

I'd presume they are out of order because when using a standard query in a database (Like Oracle) there is no guarantee of the order of the records unless you specify an "order by" clause.   Salesforce doesn't seems to be adding an order by to the subquery that is being done to get the Comment records.  So, even though they are timestamped, you can't rely on the order.

 

I agree, it would be nice if they defaulted to ordering by creation date or something reasonable, but...

 

So, no, I don't think you can accomplish this without a controller.  :-(       Best, Steve.

DanielJimenezDanielJimenez
Thanks Steve! A controller shouldn't be a big deal, just wanted to avoid it if possible.