Am working with Aggregation on an object and i have specified count field in Order By Clause. Am loading aggregate results into wrapper class. Here am not getting the values in specified order. In wrapper class am generating some string to display in visual force page. I want to sort wrapper based on that string value.
Global class QuoteViewPrint {
public string QuoteID{Get; set;}
public list<QuoteLineItem> QLI{get; set;}
public list<QuoteLineItem> QLIAggr{get; set;}
public list<QLWrap> lstWrap{get; set;}
public string accName{get; set;}
public string accPhone{get; set;}
public string MobPhone{get; set;}
public string conEmail{get; set;}
public string QuoteNo{get; set;}
public string conLastName{get; set;}
public string conFulName{get; set;}
public string accBilStrt{get; set;}
public string accBilZip{get; set;}
public string accBilCity{get; set;}
public Decimal exclPrice{get; set;}
public decimal InclPrice{get; set;}
public decimal taxAmount{get; set;}
public decimal bulkDiscount{get; set;}
public enum SORT_BY {
POS
}
public QuoteViewPrint(){
QuoteID = Apexpages.currentPage().getParameters().get('id');
system.debug('sdfsdfg'+QuoteID);
loadData();
}
//Wrapper class to load the SNO, Product details, Quantity and Image
public class QLWrap{
public string FT{get; set;}
public QuoteLineItem objWrQL{get; set;}
public integer QTY{get; set;}
public string imageURL{get; set;}
public Decimal DiscAmount{get; set;}
/* public QLWrap (string f,QuoteLineItem QT, integer q, string u, decimal d ){
FT= f;
objWrQL = QT;
QTY= q;
imageURL = u;
DiscAmount = d;
} */
}
public void loadData(){
QLI = new list<QuoteLineItem>();
lstWrap = new list<QLWrap>();
list<string> uniKey = new list<string>();
Map<string,string> unikMap = new Map<string,string>();
//Get the count of quote lines based on Name, colour, condition and condition of the product
AggregateResult[] groupedResults = [SELECT Product2.Name prdName,Product2.Colour__c clr, Product2.Condition__c cnd,Product2.Generation__c gen, Count(Pos__c)str from QuoteLineItem
where QuoteId =: QuoteID GROUP BY Product2.Name ,Product2.Colour__c, Product2.Condition__c,Product2.Generation__c order by count(Pos__c) Desc];
for(AggregateResult ar:groupedResults ){
unikMap.put((string.valueOF(ar.get('prdName'))+string.valueOf(ar.get('clr'))+string.valueOf(ar.get('cnd'))+string.valueOf(ar.get('gen'))),string.valueOf(ar.get('str')));
}
//Get all the Quote line items to get start and end numbers
QLI= [select Id,Product2Id,Product2.Name,Quote.QuoteNumber,Quote.Contact.Name,Quote.Discount_Amount__c,Quote.Bulk_Discount_Total__c,Quote.Grand_Total_Exclude__c,Quote.MWST_Calculation__c,
Quote.MwSt_Procent__c,Quote.Subtotal_Exclude__c,Quote.Total_Price_Exclude__c,//Discount_Amount__c,
Quote.Subtotal,Quote.GrandTotal,Quote.Contact.LastName,Quote.Contact.Account.billingCity,Quote.Contact.Account.billingstreet,Quote.Contact.Account.billingpostalCode,Quote.Contact.Account.Name,
Quote.Contact.Account.Phone,Quote.Contact.MobilePhone,Quote.Contact.Email,Product2.Colour__c,Product2.Product_Image__r.skuid__Url__c,Product2.Related_Image__r.skuid__Url__c,Sales_Price_Exclude__c,
LineNumber,Product2.Article_Image__c,Product2.Condition__c,PriceBookEntry.Name,Product2.Generation__c,UnitPrice,Discount_Amount__c,Bulk_Discount__c,Pos__c from QuoteLineItem
where QuoteId =:QuoteID order by Pos__c];
string strST,strND,imgURL;
QuoteLineItem objQLI = new QuoteLineItem();
boolean firstime= false;
exclPrice = 0.00;
InclPrice = 0.00;
bulkDiscount = 0.00;
for(string str:unikMap.keyset()){
imgURL = '';
QLWrap QLWrap1 = new QLWrap();
boolean uniString = false;
Decimal disAmount = 0;
system.debug('**********'+str);
for(QuoteLineItem objQL:QLI){
if(firstime == false){
accName = objQL.Quote.Contact.Account.Name;
accPhone = objQL.Quote.Contact.Account.Phone;
MobPhone = objQL.Quote.Contact.MobilePhone;
conEmail = objQL.Quote.Contact.Email;
QuoteNo = objQL.Quote.QuoteNumber;
conLastName = objQL.Quote.Contact.LastName;
conFulName = objQL.Quote.Contact.Name;
accBilStrt = objQL.Quote.Contact.Account.billingstreet;
accBilZip = objQL.Quote.Contact.Account.billingpostalCode;
accBilCity = objQL.Quote.Contact.Account.billingCity;
firstime = True;
}
if((string.valueOF(objQL.Product2.Name)+string.valueOf(objQL.Product2.Colour__c)+string.valueOf(objQL.Product2.Condition__c)+string.valueOf(objQL.Product2.Generation__c)).equals(str)){
if(uniString ==false ){
strST = string.valueOf(objQL.Pos__c);
if(objQL.Product2.Related_Image__r.skuid__Url__c != null)
imgURL = string.valueOf(objQL.Product2.Related_Image__r.skuid__Url__c);
system.debug('**********'+objQL.Pos__c);
uniString = true;
objQLI = objQL;
}
if(objQL.Discount_Amount__c != null)
disAmount += objQL.Discount_Amount__c;
strND = string.valueOf(objQL.Pos__c);
system.debug('SE no::>:::::'+strST+'--'+strND);
if(objQL.Sales_Price_Exclude__c!=null)
exclPrice = exclPrice+objQL.Sales_Price_Exclude__c;
InclPrice = InclPrice+objQL.UnitPrice;
bulkDiscount = bulkDiscount+objQL.Discount_Amount__c;
}
}
QLWrap1.FT = (strST+'-'+strND);
QLWrap1.objWrQL = objQLI;
QLWrap1.QTY = integer.valueOf(unikMap.get(str));
QLWrap1.DiscAmount = disAmount;
QLWrap1.imageURL = imgURL.removeStart('<img src="').removeEnd('" alt="[Click Here]" height="100" width="200" border="0"/>');
system.debug('####'+imgURL.removeStart('<img src="').removeEnd('" alt="[Click Here]" height="100" width="200" border="0"/>'));
system.debug('****'+imgURL);
lstWrap.add(new QLWrap());
}
taxAmount= Decimal.valueOf( (string.valueOf(InclPrice*0.08)).removeEnd('00'));
// exclPrice =Decimal.valueOf( (sting.valueOf(InclPrice*0.08)).removeEnd('00'));
// lstWrap.sort();
}
public string id;
// lstWrap.sort();
}
Here i want to sort based on Wrapper FT string.