I have a process that takes a case id from a url param through js, cases the id correctly (as ids are case sensitive), and passes it to an apex method through an action function.
This process has been working for months and with no change to any of the environments, we received incidents across partial, full, and dev sandboxes as well as production. Partial and full are on summer as well as one dev, the other dev recently refreshed to validate against is on spring.
However, the method is no longer casing the Id correctly, it is not capitalizing the 4th character in the Id. The I should be capitalized, when the I is capitalized, it finds the record and the query proceeds as expected.
This can be seen in the debug:
DEBUG|Before repair: 5003i000001gaieqa2
DEBUG|After repair: 5003i000001gAIEQA2
system.debug('Before repair: ' + caseIdToGetContactId);
caseIdToGetContactId = repairCasing(caseIdToGetContactId);
system.debug('After repair: ' + caseIdToGetContactId);
The logic I am using to correct the casing (obtained from a Stack Exchange I found some time ago, but can no longer locate):
static String CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345';
static List<Boolean> getBitPattern(String c)
{
Integer index = CHARS.indexOf(c.toUpperCase());
List<Boolean> result = new List<Boolean>();
for (Integer bitNumber = 0; bitNumber < 5; bitNumber++)
result.add((index & (1 << bitNumber)) != 0);
return result;
}
static String repairCasing(String input)
{
if (String.isBlank(input) || input.length() != 18) return input;
List<Boolean> toUpper = new List<Boolean>();
toUpper.addAll(getBitPattern(String.valueOf(input.substring(15, 15))));
toUpper.addAll(getBitPattern(String.valueOf(input.substring(16, 17))));
toUpper.addAll(getBitPattern(String.valueOf(input.substring(17, 18))));
String output = '';
for (Integer i = 0; i < 15; i++)
{
String c = String.valueOf(input.substring(i, i+1));
output += toUpper[i] ? c.toUpperCase() : c.toLowerCase();
}
output += input.substring(15, 18).toUpperCase();
return output;
}
I have a process that takes a case id from a url param through js, cases the id correctly (as ids are case sensitive), and passes it to an apex method through an action function
. What does your Apex do? normal selects work without dealing with this problem client side at all. Pass either 15 or 18, it will work fine.Id myId
(notString myId
) i do not need to handle conversion