@RestResource(urlMapping='/Xin_SearchOpportunity/*') global with sharing class Xin_SearchOpportunityRest { @HttpPost global static void doPost(String query, String visitorPlaceId) { system.debug('Xin_SearchOpportunityRest.start'); Xin_SearchOpportunity ctl = new Xin_SearchOpportunity(); ctl.search(query, visitorPlaceId); // 検索結果をMapのListに変換 List> rsList = new List>(); for (Opportunity sobj : ctl.results) { Map rs = new Map(); 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 + '(' + sobj.Department_Name__c + ') ' + sobj.StageName + ' ' + sobj.Opportunity_No__c); 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; } }