Wrapper Class Multiple Value Sorting | sfdcFanBoy
文章推薦指數: 80 %
Came across a scenario where I had to sort a wrapper class. Normal list sorting is simple, list.sort(); would help. But for a wrapper class, ... Skiptocontent CameacrossascenariowhereIhadtosortawrapperclass. Normallistsortingissimple,list.sort();wouldhelp. Butforawrapperclass,it’snotstraight-forwardbutitisn’tthathard. Belowisasimple wrapperclasswithoutsorting–thiswrapperhas2columns:AreaandAD. globalclassAreaWrapper{ publicStringAreaName{get;set;} publicStringADName{get;set;} publicAreaWrapper(){ AreaName=''; ADName=''; } } Tomakeitsort byADName,weneedtheclasstouse“implements Comparable”and “CompareTo”. globalclassAreaWrapperimplementsComparable{ publicStringAreaName{get;set;} publicStringADName{get;set;} publicAreaWrapper(){ AreaName=''; ADName=''; } globalIntegercompareTo(ObjectobjToCompare){ //SortbyAreaNameAlphabetically returnAreaName.compareTo(((AreaWrapper)objToCompare).AreaName); } } Ifyouwanttoaddanothersort(withinAreaNamesorting)i.e., ifyouwanttosortbyAreaNameandthenbyADName,thisworks. globalIntegercompareTo(ObjectobjToCompare){ AreaWrapperthat=(AreaWrapper)objToCompare; Integerc=this.AreaName.compareTo(that.AreaName); if(c!=0){ returnc; }else{ returnthis.ADName.compareTo(that.ADName); } } Anddonotforgettosortthewrapperlistbeforedisplayinginvisualforcepage. publicListAreaWrappermyWrapperList{ get{ myWrapperList.sort(); returnmyWrapperList; } privateset; } Showyourlovebysharingthis:ClicktoshareonFacebook(Opensinnewwindow)ClicktoshareonTwitter(Opensinnewwindow)ClicktoshareonLinkedIn(Opensinnewwindow)ClicktoshareonWhatsApp(Opensinnewwindow)ClicktoshareonTumblr(Opensinnewwindow)Clicktoemailthistoafriend(Opensinnewwindow)Clicktoprint(Opensinnewwindow)MoreClicktoshareonPinterest(Opensinnewwindow)ClicktoshareonPocket(Opensinnewwindow)ClicktoshareonTelegram(Opensinnewwindow)ClicktoshareonSkype(Opensinnewwindow)ClicktoshareonReddit(Opensinnewwindow)Likethis:LikeLoading... Related OneReplyto“WrapperClassMultipleValue Sorting” Pingback:WrapperClassMultipleValue Sorting|SutoComSolutions LeaveaReplyCancelreply Enteryourcommenthere... Fillinyourdetailsbeloworclickanicontologin: Email(required)(Addressnevermadepublic) Name(required) Website YouarecommentingusingyourWordPress.comaccount. ( Log Out / Change ) YouarecommentingusingyourGoogleaccount. ( Log Out / Change ) YouarecommentingusingyourTwitteraccount. ( Log Out / Change ) YouarecommentingusingyourFacebookaccount. ( Log Out / Change ) Cancel Connectingto%s Notifymeofnewcommentsviaemail.Notifymeofnewpostsviaemail. Δ Postnavigation PreviousPostPreviousNewUIfor SalesforceNextPostNextDreamforceWrapUp 2015! SearchBlog Searchfor: Search RankedinTop10SalesforceDeveloperBlogs RankedinTop50SalesforceBlogs RECENTPOSTS MaketheMostofMarketingCloudwiththesePro Tips March3,2022 HowtoConnectSalesforceto LinkedIn October7,2021 NetSuiteSalesforceIntegration:CustomBuiltvsThirdParty Solutions May15,2021 TOP3SalesforceMarketingCloudFeatures–January Release February1,2021 ATipADay#39–EasilyFindNewlyCreatedFieldsin Salesforce January25,2021 GetSalesforceMarketingCloud Certified November14,2020 MarketingCloudvsPardot:ChoosingaSalesforcePlatformforYour Business November8,2020 SalesforceConfigurationandCustomization: Comparison November8,2020 MarketingCloudAdministratorCertification Preparation November6,2020 ConversationalCommerceinSalesforceMarketing Cloud July3,2020 FollowsfdcFanBoyonWordPress.com FollowBlogviaEmail Enteryouremailaddresstofollowthisblogandreceivenotificationsofnewpostsbyemail. EmailAddress: Follow RecentComments sfdcFanBoyonATipADay#16–Report…sfdcFanBoyonVisualforceEmailTemplatewit…VishalSinhasanonEinsteinFeaturesGuide…FelixEonVisualforceEmailTemplatewit…fieldassistapponSalesforceMarketingCloud… TOPPOSTS 7WaystoLockaRecordinSalesforce DeployCustomMetadataTypeRecords MaketheMostofMarketingCloudwiththeseProTips SalesforceMarketingCloudInterviewQuestions&Answers EinsteinFeaturesGuide-SalesforceMarketingCloud Categories ATipADay(40) Apex(28) apexcallout(2) ApexDataLoader(3) Bootstrap(2) Certification(48) Chatter(1) Configuration(8) CPaaS(1) CustomMetadataType(1) Customize(21) Deployment(6) DeploymentManager(1) DeveloperConsole(2) Dreamforce(6) DuplicateManagement(1) Einstein(4) Events(10) GoogleAnalytics(1) GuestPost(1) Idea(8) Integration(1) Interviews(19) LightningAppBuilder(4) LightningDataService(1) LightningExperience(18) LightningFlowBuilder(1) LWC(1) MarketingCloud(27) MVPInterviews(13) MyInterviews(5) NamedCredentials(2) Pardot(1) PatternMatch(2) RegularExpressions(2) Releases(29) Reports(6) Salesforce(178) SalesforceEditions(2) SalesforceScanners(3) SalesforceShield(1) SalesforceDX(2) SOQL(10) Spring16(1) Spring17(4) Spring18(4) Spring19(2) Summer17(1) Summer18(4) Tools(11) Uncategorized(3) Userinterface(2) Validationrule(2) Visualforce(7) Winter18(3) Winter20(2) workflow(1) CONTACTMEViewsfdcfanboy’sprofileonFacebookViewsfdcfanboy’sprofileonTwitterViewmanishthaduri’sprofileonLinkedInViewsfdcfanboy’sprofileonGitHubViewmanishthaduri’sprofileonGoogle+Viewmanisht’sprofileonWordPress.orgViewsfdcfanboy’sprofileonTumblrTranslatetoyourLanguageBlogStats 1,030,637hits FollowmeonTwitterMyTweets Follow Following sfdcFanBoy Join611otherfollowers Signmeup AlreadyhaveaWordPress.comaccount?Loginnow. sfdcFanBoy Customize Follow Following Signup Login Copyshortlink Reportthiscontent ViewpostinReader Managesubscriptions Collapsethisbar SendtoEmailAddress YourName YourEmailAddress Cancel Postwasnotsent-checkyouremailaddresses! Emailcheckfailed,pleasetryagain Sorry,yourblogcannotsharepostsbyemail. Privacy&Cookies:Thissiteusescookies.Bycontinuingtousethiswebsite,youagreetotheiruse. Tofindoutmore,includinghowtocontrolcookies,seehere: CookiePolicy %dbloggerslikethis:
延伸文章資訊
- 1How to sort wrapper class list in Salesforce? - InfallibleTechie
How to sort wrapper class list in Salesforce? Comparable Interface is used to sort wrapper class ...
- 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...
- 3How can I Sort Wrapper list in Salesforce? - Forcetalks
Hi,. You can use the sort() method of Salesforce List class. sort() : Sorts the items in the list...
- 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 ...
- 5Custom Sort Wrapper Class - Salesforce Developer Community
I created a wrapper class that implements the Comparable interface. However, when I sort the list...