I am new to Apex. I have a SOQL query like SELECT Session_Id__c FROM Device__c WHERE User_Id__c = :userid. In this User_id__c is custom field defined datatype as Text and userid is id of user. Is that qury works or do i need to do anything else? I believe it is not working as expected.I will appreciate help.
[SalesForce] comparing id field with string field in soql query
Related Topic
- [SalesForce] Perform a SOQL Query LIKE Specifically for Lowercase
- [SalesForce] SOQL query with Map keyeset
- [SalesForce] How to perform Fuzzy search in a string field
- [SalesForce] SOQL: Inner query on lookup field
- [SalesForce] SOQL: Comparing two custom relationship fields in a nested query
- [SalesForce] SOQL query on date field WHERE by year
Best Answer
Yes, it should work just fine, assuming you're using 18-character ID values exclusively. Since queries are case insensitive, if you're only using the 15-character ID values in your text field, you'll get invalid results. I know I've seen a lot of questions where people intentionally remove the "extra" three characters from the end of ID values for some reason or another, but that will mess up queries like this one.