Skip to main content
1 of 2

SOQL SELECT query failing with 'No search term found. The search term must be enclosed in braces.'

I have a Kotlin application that uses Fuel for making HTTP requests to the Salesforce API. One of the HTTP requests that uses a SOQL SELECT query is failing, and I'm not sure why.

            val searchForUsernameSoqlQuery = "SELECT Username From User"

            val existingUser = crmService.getIntegrationUser( 
            searchForUsernameSoqlQuery, 
            token!!,
            existingInstanceResource.tenantUrl,
            ctx.orgId()
        )

getIntegrationUser() runs through some middleware and ends up calling this search function:

    suspend fun search(
    query: String,
    authToken: AuthenticationToken,
    tenantUrl: String,
    orgId: Int
): JsonArray? {
    val request = Fuel
        .get("$tenantUrl/services/data/$API_VERSION/search", listOf("q" to query))
        .header(
            mapOf(
                "Authorization" to "${authToken.tokenType} ${authToken.accessToken}",
                "Target-URL" to tenantUrl,
                "Accept" to "application/json"
            )
        )

    val (_, response, result) = datadog.time(
        "sfdc-search",
        "organisation:$orgId"
    ) { request.awaitStringResponseResult() }

'result' is an error, with the narrative 'No search term found. The search term must be enclosed in braces.'

After searching for clues on this error, I know it can relate to special characters in the search term, but here I'm not even using a WHERE clause to filter on specific strings, so special characters isn't an issue (although if I add a basic WHERE clause, which I want to do eventually, the same error occurs).

Testing the SOQL query on Workbench works fine with no issues. And, if I change the SELECT to a basic FIND query, I get the correct result returned with no problems. This, combined with the fact that the existing code has been working fine for other operations, including SELECT operations for a while now, means that I'm confident that none of the other code is the issue. I'm also sure I am passing the correct arguments to the search function (other than the query). So it must be something to do with the construction of the SELECT query, but I'm at a loss as to what it could be as it's so simple.

I've tried enclosing the whole thing in brackets, using triple speech marks around the whole query, but no luck. Any help is appreciated.