0

I have an apex:dataTable to display a table of jobs. In the job object there is a status field. My scenario is I want to display all the cancelled jobs at the bottom of the table. Is it possible to do that?

3

One of the approach that I am familiar to achieve this is use list property

List<job> lstcancelledjobs=new List<job>();
List<job> lstotherjobs=new List<job>();
List<job> finallist=new List<job>();
for(job j:lstjobs){
   if(j.status=='Cancelled'){
       lstcancelledjobs.add(j);
   }else{
        lstotherjobs.add(j);
   }
}
 finallist.addAll(lstotherjobs);
 finallist.addAll(lstcancelledjobs);

Here Job is assumed object name .Also if cancelled comes last then use SOQL order by Status and ASC

[Select Status,Id from Asyncjob order by status ASC];

If you prefer not to loop you can use two queries and join them using list Add All property

  • Mohith -- don't you mean list addAll() method ? (not property) -- and the last code fragment is for AsyncJob, not Job__c – cropredy Dec 31 '14 at 19:20
  • Yes its AddAll method and yes job i clarified.I took as an example and it has to be exact table name – Mohith Shrivastava Dec 31 '14 at 19:33
  • ah, perhaps - it wasn't clear from OP that it was talking about SFDC async jobs or just 'jobs' as in work orders. – cropredy Dec 31 '14 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.