高章伟
2022-02-18 8b5f4c6c281cfa548f92de52c8021e37aa81901e
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
@RestResource(urlMapping='/Xin_SearchVisitorPlace_Campaign/*')
global with sharing class Xin_SearchVisitorPlace_CampaignRest {
 
    /**
     * reportDate yyyy/MM/dd
     */
    @HttpPost
    global static void doPost(String query, String reporterState, String reportDate) {
        system.debug('Xin_SearchVisitorPlace_CampaignRest.start');
        Xin_SearchVisitorPlace_Campaign ctl = new Xin_SearchVisitorPlace_Campaign();
        ctl.search(query, reporterState, reportDate);
        // 検索結果をMapのListに変換
        List<Map<String, String>> rsList = new List<Map<String, String>>();
        for (Campaign sobj : ctl.results) {
            Map<String, String> rs = new Map<String, String>();
            if (rsList.size() == ctl.results.size() - 1 && ctl.getIsOverLimit() == true) {
                rs.put('Id', '');
                rs.put('Name', '');
                rs.put('DisplayName', '检索结果超过了30件');
                rsList.add(0, rs);
            } else {
                rs.put('Id', sobj.Id);
                rs.put('Name', sobj.Name);
                rs.put('DisplayName', sobj.Name);
                rsList.add(rs);
            }
        }
        // JSONを戻す
        RestResponse res = RestContext.response;
        res.addHeader('Content-Type', 'application/json');
        res.statusCode = 200;
        String jsonResponse = '{"status": "Success", "Message": ' + JSON.serialize(rsList) + '}';
        res.responseBody = blob.valueOf(jsonResponse);
        return;
    }
}