function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Luke Higgins 23Luke Higgins 23 

String not recognized in SOQL query on HTTP GET request

I'm trying to grab the record id of a Timesheet and create a related Approval Log object through a GET request. When testing, the SOQL query is returning no results although I know that the string inserted is a valid Timesheet id

Apex Class:
@RestResource(urlMapping='/approve/*')
global with sharing class exAppClass {
  jstcl__TG_Timesheet__c ts = new jstcl__TG_Timesheet__c();
        // GET request
       @HttpGet
        global static jstcl__TG_Timesheet__c doGet() {
          RestRequest req = RestContext.request;
          String tsid = req.requestURI.substring(req.requestURI.lastIndexOf('/')+1);

          System.debug(tsid);
          jstcl__TG_Timesheet__c ts = [SELECT Id, jstcl__Week_Ending__c FROM jstcl__TG_Timesheet__c WHERE Id = :tsid];
          insertLog(ts);
          return ts;
        }
        private static Express_Approval_Log__c insertLog(jstcl__TG_Timesheet__c ts){
          Express_Approval_Log__c log = new Express_Approval_Log__c();
          log.Name = 'EAL '+ts.jstcl__Week_Ending__c;
          log.Timesheet__c = ts.Id;
          insert log; 
          return log;
      }
  }

 
ShirishaShirisha (Salesforce Developers) 

Hi Luke,

Greetings!


I would suggest you to add the debug statements to check the value of the String which you are trying to pass to make sure the string is valid.

Once,you add the debug statement then capture the debug logs to check the code execution.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri

Abhishek BansalAbhishek Bansal
Hi Luke,

Can you please check if you are passing 15-digit id or 18-digit id? In the database the id is stored in 18 characters so please make sure that you are passing 18-digit id. Or you can change the SOQL filter to like instead of =

Let me know if you need any further help or information on this.

Thanks,
Abhishek Bansal.
Luke Higgins 23Luke Higgins 23
Abhishek - it is passing the 18 digit ID
Abhishek BansalAbhishek Bansal
Hi Luke,

I can see you have a debug log at the line no. 10. Did you check this debug log? Please copy the id from this debug log and execute the same query in the developer console. You will surely find out what's going wrong.
If you still face the issue, please add the results from both the debug logs and dev console query so that we can look into it.

Thanks,
Abhishek Bansal.