Search code examples
apisalesforcesoql

Salesforce API: How to retrieve a Case using a partial Case Id


I'd like to retrieve a Case record from the Salesforce API. I only have the beginning of the Case Id (don't ask why) so I've tried the following query:

SELECT Id FROM Case WHERE Id LIKE 'whatever...%'

Unfortunately, this returns the following error:

SELECT Id FROM Case WHERE Id LIKE '500DABCD...%'
                          ^
ERROR at Row:1:Column:27
invalid operator on id field'
How can we get this functionality from the API?

Why can't I use the LIKE operator on the Id field? Is there some other way I can do this?


Solution

  • I've found a workaround: I've added a custom field to the Case entity that mirrors the Id field. I've found that (unlike the original Id field) I can query this field with the LIKE operator.

    The field is of type "Formula (Text)" and I've set the formula to simply be "Id".