Sorting objects in list according to othe fields - Salesforce ...

文章推薦指數: 80 %
投票人數:10人

Use ORDER BY clause and directly store sorted results in the list. ... 2. Another possible way is to add the data to a Map and sort by keyset. LoginwithSalesforce Don'thaveanaccount? SignupforaDeveloperEdition BrowsebyTopic ApexCodeDevelopment(86622) GeneralDevelopment(53776) VisualforceDevelopment(36733) APIsandIntegration(15806) Lightning(15647) Trailhead(11258) Formulas&ValidationRulesDiscussion(10640) OtherSalesforceApplications(7731) JobsBoard(6626) Force.comSites&Site.com(4714) Mobile(2608) JavaDevelopment(3888) .NETDevelopment(3500) Security(3170) Mobile(2608) VisualWorkflow(2338) AppExchangeDirectory&Packaging(2325) Perl,PHP,Python&RubyDevelopment(2012) ChatterandChatterAPIDevelopment(1702) SalesforceLabs&OpenSourceProjects(1215) DesktopIntegration(1140) Architecture(926) SchemaDevelopment(912) Apple,MacandOSX(791) VBandOfficeDevelopment(633) EinsteinPlatform(188) Salesforce$1MillionHackathon(180) SalesforceSummerofHacks(173) ViewMoreTopics SeeAllPosts Ask Search: ResetSearch WelcometoSupport! SearchforanansweroraskaquestionofthezoneorCustomerSupport. Needhelp? Dismiss Youneedtosignintodothat Signintostartsearchingquestions Don'thaveanaccount? SignupforaDeveloperEdition ShowAllQuestionssortedbyDatePosted ShowAllQuestionsUnansweredQuestionsUnsolvedQuestionsSolvedQuestions sortedbyDatePostedRecentActivityMostPopular +StartaDiscussion Youneedtosignintodothat Signintostartadiscussion Don'thaveanaccount? SignupforaDeveloperEdition SolvedQuestionsThisQuestion ArunYadav13 SortingobjectsinlistaccordingtoothefieldsHiIneedtoSortentriesofquoteLineItemListbyPriceBookEntry.Product2.Product_Family__r.Sort_Order__candPriceBookEntry.Product2.ProductCodeandthenstorethesortedlistinorderedLineItem.HowcanIdothisusingapexcode. May16,2016·Like0·Follow1 BestAnswerchosenbyArunYadav13MedhyaMahajan//AssumingPriceBookEntry.Product2.Product_Family__r.Sort_Order__cisoftypeString MapproductFamilyMap=newMap();MapproductFamilyMapSorted=newMap();ListorderingList=newList();ListsortedQuoteLineItemList=newList();                      for(QuoteLineItemqliObj:quoteLineItemList){                      productFamilyMap.put(qliObj.PriceBookEntry.Product2.Product_Family__r.Sort_Order__c,qliObj);           }   //AddallelementsofSetintoalist           orderingList.addAll(productFamilyMap.keyset());           //SorttheList   orderingList.sort();            for(Integeri=0;iproductFamilyMap=newMap();MapproductFamilyMapSorted=newMap();ListorderingList=newList();ListsortedQuoteLineItemList=newList();                      for(QuoteLineItemqliObj:quoteLineItemList){                      productFamilyMap.put(qliObj.PriceBookEntry.Product2.Product_Family__r.Sort_Order__c,qliObj);           }   //AddallelementsofSetintoalist           orderingList.addAll(productFamilyMap.keyset());           //SorttheList   orderingList.sort();            for(Integeri=0;i



請為這篇文章評分?