liuyn
2024-03-11 a87f1c3df03078814ee97ad0c8ac200a232419e9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
public with sharing class RecordLastCtl {
    public RecordLastCtl() {
 
    }
    @AuraEnabled(cacheable=false)
    public static List<RecentlyViewedStr> getRecentlyViewedListView(){
        List<RecentlyViewedStr> rvList = new List<RecentlyViewedStr>();
        Map<String,String> iconMap = new Map<String,String>();
        List<RecentlyViewed> resultList = [SELECT Id, Name, Type, LastViewedDate, LastReferencedDate FROM RecentlyViewed WHERE NOT Name like '%主页用%' order by LastViewedDate desc limit 20];
        List<TabDefinition> tabList = [SELECT (SELECT ContentType, Url FROM Icons WHERE ContentType LIKE 'image/svg%'),SobjectName FROM TabDefinition];
        if (resultList!=null && resultList.size() > 0) {
            if (tabList.size() > 0) {
                for (TabDefinition tab : tabList) {
                    if (tab.Icons.size() > 0) {
                        iconMap.put(tab.SobjectName, tab.Icons[0].Url.split('35/')[1].split('.svg')[0].replace('/',':'));
                    }
                }
            }
            for (RecentlyViewed rv : resultList) {
                RecentlyViewedStr rvStr = new RecentlyViewedStr();
                rvStr.id = rv.Id;
                rvStr.name = rv.Name;
                rvStr.type = rv.Type;
                SObjectType sObj = Schema.getGlobalDescribe().get(rv.Type);
                rvStr.type = sObj.getDescribe().getLabel();
                rvStr.amount = '/lightning/r/'+ rv.Id+'/view';
                if (String.isNotBlank(iconMap.get(rv.Type))) {
                    rvStr.ico = iconMap.get(rv.Type);
                } else {
                    rvStr.ico = 'custom:custom100';
                }
                rvList.add(rvStr);
            }
        }
        return rvList;
    }
    public class RecentlyViewedStr {
        @AuraEnabled
        public String id;
        @AuraEnabled
        public String name;
        @AuraEnabled
        public String type;
        @AuraEnabled
        public String expectedRevenue;
        @AuraEnabled
        public String amount;
        @AuraEnabled
        public String ico;
    }
}