You need to sign in to do that
Don't have an account?
Prazzie
Sorting records using StandardSetController
Hi,
I am using the following code. Yet the order of the records is not fetched according to the query. When I run the query independently it is providing right results. How to get rid of the problems?
class
public List<Utility_Object__c> getUnIdenfiedEntries() { return (List<Utility_Object__c>) setCon.getRecords(); } public ApexPages.StandardSetController setCon { get { if (setCon == null) { setCon = new ApexPages.StandardSetController(Database.getQueryLocator( [Select salesAmount__c,Reported_Buyer__c From Utility_Object__c where Related_Account__c = :accountId AND Report_Level__c=:DISTI_VAL Order by salesAmount__c desc limit 100])); setCon.setPageSize(this.pageSize); this.recordCount = setCon.getResultSize(); } return setCon; } set; }
page
<apex:pageBlockTable value="{!unIdenfiedEntries}" var="entry" id="entryList"> <apex:column headerValue="Reported Buyer" value="{!entry.Reported_Buyer__c}"/> <apex:column headerValue="Sales" value="${!entry.salesAmount__c}"/> </apex:pageBlockTable>
Help will be appreciated
What order is the set controller picking up then if not that of salesAmount__c?
look like a random one...it is taking the amount which close to the highest sales amount but not the highest one actually
Well that's probably because of the LIMIT 1000. It will pick the first 1000 records and sort them, so if the highest record is outside that 1000, well, it won't get included. When you put a limit in there, the limit is applied *before* the sort, not after it.
That is unlikely because when I am using the same query without StandardSetController the sorting order seems to be right
A fair point. What happens if you create the StandardSetController from a List<Utility_Object__c> instead of from the query locator? It shouldn't really make a difference but you never know.
Nope..it's also not working :(