How can I Sort Wrapper list in Salesforce? - Forcetalks
文章推薦指數: 80 %
Hi,. You can use the sort() method of Salesforce List class. sort() : Sorts the items in the list in ascending order. Thanks ...
Activity›Forums›Salesforce®Discussions›HowcanISortWrapperlistinSalesforce?
Tagged: SalesforceCustomization,SalesforceDevelopment,WrapperClass,WrapperList
HowcanISortWrapperlistinSalesforce?
Parulupdated3years,5monthsago
4Members
·
4
Posts
Salesforce®Discussions
SalesforceCustomizationSalesforceDevelopmentWrapperClassWrapperList
PRANAV
MemberSeptember8,2016at2:24pm
HiAll,
HowcanISortWrapperlist?
Ihavemadeawrapperclassinwhichthereisalistofsearchedproducts,Iwanttodisplaythosesearchedresultinascendingorderoftheirname.
Thanks
Mohit
MemberSeptember16,2016at6:45am
HiPranav,
Hereisthecodeforsortingthewrapperlist:-
globalclassBookimplementsComparable{
publicStringBookTitle;
publicStringAuthor;
publicIntegerTotalPages;
publicDoublePrice;
publicDatepublishingDate;
publicenumSORT_BY{
ByTitle,ByPage
}
//Variabletodecidethememberonwhichsortingshouldbeperformed
publicstaticSORT_BYsortBy=SORT_BY.ByTitle;
publicBook(Stringbt,Stringa,Integertp,Doublep,Datepd)
{
BookTitle=bt;
Author=a;
TotalPages=tp;
Price=p;
publishingDate=pd;
}
globalIntegercompareTo(ObjectobjToCompare){
//SortbyBookNameAlphabetically
if(sortBy==SORT_BY.ByTitle)
{
returnBookTitle.compareTo(((Book)objToCompare).BookTitle);
}
else//SortbyBookprice
{
returnInteger.valueOf(Price-((Book)objToCompare).Price);
}
}
}
shariq
MemberSeptember19,2018at1:13pm
Hi,
Youcanusethe sort()methodofSalesforceListclass.
sort():
Sortstheitemsinthelistinascendingorder.
Thanks
Parul
MemberSeptember22,2018at5:25am
Addingsomepointsandcodesnippet:
37downvote
Apexprovidesa sortmethod ontheListclassforsorting.Forobjectssuchasthishowever,youmustimplementthe Comparable interface.NotetheSalesforcedocsamplesindicateyouneedtomakeyourclass'global'scope,thisisnolongertrue.
publicclassjobsWrapperimplementsComparable
{
publicIntegercompareTo(ObjectcompareTo)
{
jobsWrapperjobsWrapper=(jobsWrapper)compareTo;
if(job.Name==jobsWrapper.job.Name)return0;
if(job.Name>jobsWrapper.job.Name)return1;
return-1;
}
}
Thenonceyouputyourobjectsintoalistyoucanusethesortmethod.
List
延伸文章資訊
- 1How to Sort Wrapper class Collection in Apex - Salesforce ...
Sorting of Primitive Data Types like <String> (eg. List of student names) is easy in collection. ...
- 2Sorting Wrapper List in ASC or DESC order based on ...
I have added a static method which can be called from developer console to see the output for ref...
- 3Sort wrapper class list in Apex - SFDC Lessons
Sort wrapper list based on selected records. Visualforce page: My Product Select Name Product Fam...
- 4How to sort Wrapper list? - apex - Salesforce Stack Exchange
Apex provides a sort method on the List class for sorting. For objects such as this however, you ...
- 5Sort Wrapper Class In Apex - SFDC Knowledge Articles
A very interesting requirement i came through today ie to sort a wrapper record list. While explo...