4

I have a soql query

 private static String selectQuery = 'select name,uw_Brand__r.Banner_Location__c,Inherit_Branding__c,Sharing__c,ownerid,Banner_1_Location__c,Description__c,LastModifiedById,Release_Date__c,Category_Level_2__c ,(select id from  assets__r where uw_BET__c in :betids), ( Select SubscriberId ,parentid From feedsubscriptionsforentity  where parentid in :betids) from uw_BET__C where id in :betids ORDER BY name limit :list_size offset :counter';

Can i sort this query based on number of assets returned from first subquery 1 and number of subscriberid returned from subquery 2.

I dont want to alter datamodel-by adding roll up summary field

3
  • always config is better than code.roll up summaries are great to use if that helps Dec 8, 2013 at 17:09
  • If you're set against using rollups, then I would suggest using a wrapper class. I'll see if I can throw some code together Dec 8, 2013 at 18:21
  • hmm..its currently lookup relationship.so changing it into master and then adding rollup summary will be a big change.so wrapperclass sorting could be the best option
    – sfdc99999
    Dec 8, 2013 at 18:29

1 Answer 1

3

Instead of a list of your uw_Bet Object, you would have a list of your new wrapper class. I implemented the comparable interface so you could easily sort the list of wrapper by whatever you like. You just need to implement the compareTo method however you want. Right now its sorting by the assets list size.

list<myWrapper> wraps = new list<myWrapper>();
for(uw_BET__c bet: **yourQuery**)(
     wraps.add(new myWrapper(bet));
}
wraps.sort();


public class myWrapper implements Comparable {
    public uw_BET__C myBet          {get;set;}

    public myWrapper(uw_BET__C bet){
        myBet = bet;
    }

    public Integer compareTo(Object compareTo) {
        uw_BET__C betComp = (uw_BET__C)compareTo;
        if (myBet.assets__r.size() == betComp.assets__r.size()){
            return 0;
        } 
        if (myBet.assets__r.size() > betComp.assets__r.size()){
            return -1;
        }
        return 1;  
    }
}

You must log in to answer this question.

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