2

This is more of a conceptual question. I was initially querying attachments related to a specific object like this -

SELECT Id, Name, ParentId, Description, BodyLength,IsDeleted,IsPrivate,CreatedById,CreatedDate FROM Attachment where 
 ParentId IN (Select Id from my_custom_object__c)

but it kept timing out in workbench. So someone gave me wonderful idea to write query like this

SELECT Id, Name, ParentId, Description, BodyLength,IsDeleted,IsPrivate,CreatedById,CreatedDate FROM Attachment where  (ParentId > ‘a1e000000000000000’) AND (ParentId <‘a1ezzzzzzzzzzzzzzz’)

where a1e is the object prefix of my_custom_object__c.

So we kind of define a custom range a1e000000000000000 to a1ezzzzzzzzzzzzzzz, where all records of my_custom_object__c are bound to be in (as in their IDs will be in this range)

This works well. But then i started to think, which is higher "max range" - a1ezzzzzzzzzzzzzzz or a1eZZZZZZZZZZZZZZZ

I tested with one particular Id (just picked up a random contact record), and wrote following code in dev console -

//Id of a contact record
Id tempId = '0032900000EbFYyAAN';
//change capital E to small e and compare
if(tempId > '0032900000ebFYyAAN'){System.debug('@@@ capital is greater');}
if(tempId < '0032900000ebFYyAAN'){System.debug('@@@ small is greater');}
if(tempId == '0032900000ebFYyAAN'){System.debug('@@@ same');}

And it printed @@@ small is greater

So does that mean, as far as comparison of IDs go, small letters are always evaluated to be bigger than capital letters? From this one test, can i assume that it is indeed the case all the time? How does salesforce internally compare two IDs?

EDIT - After reading some comments, I guess when i write where (ParentId > ‘a1e000000000000000’) AND (ParentId <‘a1ezzzzzzzzzzzzzzz’) , i am comparing ID with string. But the question stays the same - how does it work? Am i covering entire range of records when i write this? or do i need to change it to capital Z. And to clarify, queries are being run via workbench, not inside apex code

  • While ids are unique they are not guaranteed to be in chronological order. Just something to keep in mine. – Eric Jul 5 at 5:42
  • @Eric then again, they do recommend to use id forward paging in LDS docos.. – zaitsman Jul 5 at 5:55
  • I guess I should say sequentially rather than chronological. Depending on you rage the may not matter – Eric Jul 5 at 5:59
  • did you try to compare Id with Id (because now it seems they Id with String is compared)? – kurunve Jul 5 at 6:06
  • You've used the 18 character ID form which exists to make the ID case insensitive. What happens if you do this with the 15 character form? (And make sure you do compare ID to ID, not ID to String as @kurunve mentioned) – Phil W Jul 5 at 6:29
2

Do you know about ASCII? Here is a reference for it. From the ASCII table, you can see that 'E' is 69 and 'e' is 107. When you compare two string, they will be transferred at first to ASCII value and then compare them. That's why did you get the result of 'small is greater'.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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