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


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.

  • there are tons of articles explaining the diff btw 15 and 18 digit and when to use. read this blog astadiaemea.wordpress.com/2010/06/21/…
    – Rao
    Sep 25, 2015 at 21:15
  • 1
  • I would highly recommend saving the DeveloperName of your RecordType as the Custom Setting name instead of its Id.
    – Adrian Larson
    Sep 25, 2015 at 21:30
  • 1
    Just strip of the last three characters, or, use the record type name, like I suggested earlier. Trust me, you'll save yourself a lot of trouble by using names instead of ID values.
    – sfdcfox
    Sep 25, 2015 at 21:34
  • 1
    Name is not unique. DeveloperName would be much less confusing.
    – Adrian Larson
    Sep 25, 2015 at 21:36

1 Answer 1


This functionality will be much more straightforward if you just map by DeveloperName.

Name            | Case_Status__c
DeveloperName1  | Working
DeveloperName2  | In Progress

Now in your code:

My_custom_setting__c setting = My_custom_setting__c.getInstance(
if (setting != null) caseRecord.Status = setting.Case_Status__c;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .