This is a follow up from my last request - use custom settings for setting Status field of different Case Record Type
Use case - I have a piece of code, which will look at record type of current case, and will change the Status field based on case record type.I have saved the mapping of case recordtype IDs to status in a custom setting. In the code i just retrieve the status from custom setting.
I have stored some recordtype IDs in a custom setting. I get those recordtype Ids from URL. So custom setting entries look like this
my_custom_setting__c
Name | Case_Status__c
012300000009K9P | Working
012300000009C5U | In Progress
Apex code-
String query = 'SELECT RecordTypeId,Status FROM case WHERE Id = \'' + caseRecordId + '\' LIMIT 1';
//caseRecordId is obtained earlier. Its the Id of current case that is open
Case caseRecord = Database.query(query);
if(caseRecord != null){
caseRecord.OwnerId = user.Id;
my_custom_setting__c currentCustomSettingData = my_custom_setting__c.getInstance(caseRecord.RecordTypeId);
caseRecord.Status = currentCustomSettingData.Case_Status__c;
update caseRecord;
}
The issue i am facing is that RecordTypeID obtained from the query in the first 2 lines, is an 18 digit Id, example - 012300000009K9PAAu. Whereas, the Ids i stored in custom setting are obtained via URL, so they are 15 digits, example - 012300000009K9P
Due to this mismatch, i can't pull anything from the custom setting (gets null pointer).
I am looking for explanation in this mismatch between 15 digit and 18 digits, and possible solution around it.
Whats those last 3 digit about?
From URL, do we always get only 15 digits? Or in some cases it shows 18?
From SOQL query, does it always return 18 digit?
If yes, can i ALWAYS safely remove last 3 digits and then retrieve the custom setting?
Should i be concerned about situations where sometimes ID from URL (which i store in custom setting) and/or ID from query can sometimes be 15, and sometimes be 18 digits? If this is the case, some solution would be appreciated.
DeveloperName
of yourRecordType
as the Custom Setting name instead of its Id.Name
is not unique.DeveloperName
would be much less confusing.