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.

  • @sfdc fox, It is custom field defined with Text field with length of 30.before that statement i have inserted row with current user id in that custom object. – crmsj May 2 '16 at 1:49
  • be good idea to make custom field user_id__c length 18 and put a validation rule on length – cropredy May 2 '16 at 4:07

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.

Your Answer

 
discard

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.