I have an Account hierarchy. I have a formula on my Account that returns the ID of the Account at the top of the hierarchy. Due to formula size restraints, I can't use
CASESAFEID in the formula, so it only returns the 15 character ID. Return type of the formula is Text (String).
My use case is given one Account, return all the Accounts in its hierarchy. The problem is, I have a 15 character ID from the formula and SOQL is not case sensitive.
So if I do something like this:
Account a = [SELECT Id, Ultimate_Parent_Id__c FROM Account LIMIT 1]; String parentId = a.Ultimate_Parent_Id__c; String query = 'SELECT Id, ' + Util.GetDynamicQueryString() + ' FROM Account WHERE Ultimate_Parent_Id__c =: parentId'; List<Account> results = Database.query(query);
This won't work because theoretically there could be multiple Accounts with that 15-character ID when it is processed case-insensitive.
Since SOQL can't compare the String values in a case sensitive manner, the only way I can think to do this is to write a trigger to stamp the 18 character ID of the ultimate parent on create or reparent.
Has anyone figured out a way around this?