+ Start a Discussion
Nihon TaisaiNihon Taisai 

@HttpDelete: how to change SOQL filter from Id to the custom External_id?

We have an example from trailhead. But how can we change Id =: recordId to the External_id =: recordId in SOQL? I think we also change the logic of our code, because if just change it - Http-service doesn't work (List is always null). Code:
    global static void deleteCase() {
        RestRequest request = RestContext.request;
        String caseId = request.requestURI.substring(
        Case thisCase = [SELECT Id FROM Case WHERE Id = :caseId];
        delete thisCase;
@isTest static void testDeleteCase() {
        Id recordId = createTestRecord();
        // Set up a test request
        RestRequest request = new RestRequest();
        request.requestUri =
            + recordId;
        request.httpMethod = 'GET';
        RestContext.request = request;
        // Call the method to test
        // Verify record is deleted
        List<Case> cases = [SELECT Id FROM Case WHERE Id=:recordId];
        System.assert(cases.size() == 0);

// Helper method
    static Id createTestRecord() {
        // Create test record
        Case caseTest = new Case(
            Subject='Test record',
        insert caseTest;
        return caseTest.Id;