public with sharing class HomeBulletinBoardController { public List hbbInfoList {get; private set;} public void init() { hbbInfoList = new List(); // TODO 公開開始日<=today && 公開終了日>today List tmpList = new List(); List pdList = [select Id, Material_open_day__c, Material_category__c, Product_document_name__c from Product_Documentation__c where Material_status__c = '公开中' order by Material_open_day__c desc limit 20]; for (Product_Documentation__c pd : pdList) { tmpList.add(new HBBInfo(pd)); } List bbList = [select Id, Board_open_day__c, Board_category1__c, Name from Bulletin_Board__c where Board_status__c = '公开中' order by Board_open_day__c desc limit 20]; for (Bulletin_Board__c bb : bbList) { tmpList.add(new HBBInfo(bb)); } List faqList = [select Id, FAQ_disclosed_day__c, Question_category__c, SolutionName from Solution where Status = 'レビュー済み' order by FAQ_disclosed_day__c desc limit 20]; for (Solution faq : faqList) { tmpList.add(new HBBInfo(faq)); } List camList = [select Id, StartDate, RecordType.Name, Name from Campaign where (Status = '公开中' or Status = '已结束' or Status = '已提交报告') order by StartDate desc limit 20]; for (Campaign cam : camList) { tmpList.add(new HBBInfo(cam)); } tmpList.sort(); // 先頭の40件だす、後ろから抽出 Integer cnt = 0; for (Integer i = tmpList.size() - 1; i >= 0; i--) { hbbInfoList.add(tmpList[i]); cnt++; if (cnt == 40) { break; } } } public class HBBInfo implements Comparable { public Id linkId {get; private set;} public Date openday {get; private set;} public String daiBunrui {get; private set;} public String bunrui {get; private set;} public String subject {get; private set;} public HBBInfo(Product_Documentation__c pd) { linkId = pd.Id; openday = pd.Material_open_day__c; daiBunrui = Schema.SObjectType.Product_Documentation__c.Label; bunrui = pd.Material_category__c; subject = pd.Product_document_name__c; } public HBBInfo(Bulletin_Board__c bb) { linkId = bb.Id; openday = bb.Board_open_day__c; daiBunrui = Schema.SObjectType.Bulletin_Board__c.Label; bunrui = bb.Board_category1__c; subject = bb.Name; } public HBBInfo(Solution faq) { linkId = faq.Id; openday = faq.FAQ_disclosed_day__c; daiBunrui = Schema.SObjectType.Solution.Label; bunrui = faq.Question_category__c; subject = faq.SolutionName; } public HBBInfo(Campaign cam) { linkId = cam.Id; openday = cam.StartDate; daiBunrui = Schema.SObjectType.Campaign.Label; bunrui = cam.RecordType.Name; subject = cam.Name; } // openday順 public Integer compareTo(Object compareTo) { HBBInfo bbInfo = (HBBInfo)compareTo; if (openday == bbInfo.openday) return 0; if (openday > bbInfo.openday) return 1; return -1; } } }