I tried make this restapex code, and tried to using SOSL to find value this is my apex code when i used SOQL and it works well.
@RestResource(urlMapping='/Account/*')
global with sharing class UT_MDM_ResponseJSON {
@HttpGet
global static Account doGet() {
RestRequest req = RestContext.request;
RestResponse res = RestContext.response;
String accountId = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
Account result = [SELECT Id, Name, Phone, Website FROM Account WHERE Id = :accountId];
return result;
}
But, i want to change from SOQL to SOSL. This is code when i tried using SOSL, but there is no result, what should i do to make it works?
@HttpGet
global static List<List<Account>> getItem(){
RestRequest req = RestContext.request;
String searchQuery=req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
List<List<Account>> itemList;
RestResponse res = new RestResponse();
RestContext.response = res;
try{
itemList = [FIND :searchQuery IN ALL FIELDS RETURNING Account(Id, Name, Phone, Website)];
res.responseBody = Blob.valueOf(JSON.serialize(itemList));
} catch(Exception e){
System.debug('Error: ' + e.getMessage());
}
return itemList;
}
in my SOQL just find by ID, but i wanted to change to SOQL so it can find id, phone, name or whatever value in field account
https://utdev.my.salesforce.com//services/apexrest/Account/0019D000008DEcZQAW -> Find by ID
https://utdev.my.salesforce.com//services/apexrest/Account/6281928731 -> Find by Phonename