How to use final text data in Query, without binding?

Hello community, I need your assistance. I'm trying to make a SOQL query to Salesforce, where I need to pass a variable. This variable is dependant on a selector that chooses a specific state. Based on the chosen state, the query changes. This method works seamlessly with any SQL request I make, but faces issues with Salesforce requests. The system informs me that I can't proceed without binding or something similar.

Interestingly, if I hardcode text like "Montana", the request is successful. However, when I include variables (which are added on the retool part), the request fails. Is there a way to convert this to a final request before it's actually sent to Salesforce?

SELECT Name, Credentials__c
FROM Account
WHERE PersonMailingState =  {{ selectState.value}}
LIMIT 200

Does not work
With error message:" Therapist' AND PersonMailingState = Montana ^ ERROR at Row:3:Column:84 Bind variables only allowed in Apex code"

BUT

SELECT Name, Credentials__c
FROM Account
WHERE PersonMailingState =  'Montana'
LIMIT 200

WOKS!!!! WHYYY???

I think you need to put single quotes around the variable for it to be valid SQL.

Instead of
PersonMailingState = {{ transformer1.value }}
Use
PersonMailingState = '{{ transformer1.value }}'

2 Likes

That's exactly what I needed thank you so much that is amazing works like a charm now thank you very much once again

1 Like