Wrapper Class - Sort List by Date
文章推薦指數: 80 %
use list.sort(); to sort your dates. Since, this sorts in ascending direction automatically, iterate through this from the last record. for (i = ...
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
RepsG WrapperClass-SortListbyDateHiGuys, IwaswonderingifanybodycanhelpmesortawrapperclassbyDate. Ihavedatafromthreeobjectgoingintoalistvariable.Howdoithensortthelistbydate(decending)? publicclasshistory{ publicString title {get;set;} publicString Description {get;set;} publicString primaryAccount {get;set;} publicdatetimecreatedDated {get;set;} publicstring modifiedBy {get;set;} publicString createdBy {get;set;} publicString HistoryType {get;set;} publicString Status {get;set;} publicinteger num {get;set;} } Thanks September4,2012·Like0·Follow0
BestAnswerchosenbyAdmin (SalesforceDevelopers) RepsGprobelmsolved.Ididntusevishalsuggestionalthoughhedidgivemealightbulbmoment. Thisismycode: Ifirstputmydatainvariable‘mhistroy’andthensortthedataintovariable‘afterSort’.IthencallafterSortinmypageblocktable privatevoidsortmhistory(){ integertargetsize=mhistroy.size(); while(afterSort.size()!=targetsize){ findMinDateValue(); } } privatevoidfindMinDateValue(){ //datetimedt=Datetime.newInstance(2999,12,31,00,00,00);//ifascending datetimedt=Datetime.newInstance(1900,12,31,00,00,00);//ifdecending integeri=0; integermini=0; for(i=0;i!=mhistroy.size();i++){ //if(mhistroy[i].createdDated>dt){//ifascending if(mhistroy[i].createdDated>dt){//ifdecending dt=mhistroy[i].createdDated; mini=i; } } afterSort.add(mhistroy[mini]); mhistroy.remove(mini); }September6,2012·Like0·Dislike0
vishal@forceIfyoucanfollowthisapproach,Ithinkitwouldwork. Createanotherlistofthesamewrapperlist(you'llhaveyoursorteddatainthisone). Now,iteratethroughcurrentlist,collectallthedatesinalist
延伸文章資訊
- 1Salesforce: How can I sort a list of dates in apex? - YouTube
Salesforce: How can I sort a list of dates in apex?Helpful? Please support me on Patreon: https:/...
- 2Sort wrapper class list in Apex - SFDC Lessons
Sort wrapper list based on selected records. ... Apex Class: /* Name: WrapperListSortCntrl Descri...
- 3Sorting of tasks in related list : r/salesforce - Reddit
Due to some customizations and decisions that were made before I took over our org, we have a str...
- 4Sorting Lists in Salesforce - Focus on Force
Created date is higher. Step 1: Create the controller with the wrapper class, the wrapper constru...
- 5How to sort list items for Date field value (Apex, Salesforce)
Sort a List of Objects by Date - java - Stack Overflow