0

The problem here is the Phone field/it is not a string field, it is throwing following error:

invalid Illegal assignment from Integer to Case

@RestResource(urlMapping='/CaseByPhone/*')
global with sharing class CaseByPhone{

    @HttpGet
    global static Case doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        caseId= req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
          Case result = [SELECT COUNT() From Case  WHERE Asset.Phone= :caseId];
        return result;
    }

}
1
  • COUNT() in query returns an integer, if you want to retrieve an object query its desired fields.
    – Raul
    Oct 18, 2017 at 10:49

1 Answer 1

2

COUNT() query returns an integer so following query would fail:

Case objCase = [SELECT COUNT() FROM Case];

If you need to retrieve an object, query desired fields:

Case objCase = [SELECT Id, CaseNumber FROM Case LIMIT 1];

For your code to run you need to modify it to an return Integer:

@RestResource(urlMapping='/CaseByPhone/*')
global with sharing class CaseByPhone{

    @HttpGet
    global static Integer doGet() {
        RestRequest req = RestContext.request;
        RestResponse res = RestContext.response;
        caseId= req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);
        Integer resultCount = [SELECT COUNT() From Case  WHERE Asset.Phone= :caseId];
        return resultCount;
    }

}

Note: Do not forget to add exception handling when you make a query or in general

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .