Force.com & Case-Sensitivity

pnf2ycurh4The Force.com platform is case-insensitive. Mostly. It’s difficult to find information on which areas are case-sensitive so I’ve compiled this list of what I’ve discovered thus far(I’ll add notable cases as I encounter them).

Things that are case-sensitive

  • The name attribute of <apex:define> when referring to a <apex:insert> name. A suitable example might be, your application uses a VisualForce page as a template and this template has a <apex:insert> tags which allow you to merge your content with the template. The template code might be

    <apex:page id=”MyTemplate”>

    <apex:sectionHeader title=”The Heading”/>

    <apex:insert name=”Content”/>

    </apex:page>

    And the page using the template

    <apex:page>

    <apex:composition template=”MyTemplate”>

    <apex:define name=”Content”>

    <apex:outputText value=”Custom Content” />

    </apex:define>

    </apex:composition>

    </apex:page>

    Note the name of the <apex:insert> tag is ‘Content’. Were you to change the name of the <apex:define> to ‘cOTenT’ your define would be ignored. This behaviour isn’t obvious, nor is it consistent since the string value used by the template attribute of <apex:composition> is case-insensitive. It’s these sorts of quirks that keep a developer’s life interesting. Well, not so much interesting as OMG I’ll kill you frustrating.

  • Set values and Map keys. This one is straight forward. This set contains two items which aren’t the same
    static testMethod void setTest(){
    Set<String> mySet = new Set<String> {‘a’, ‘A’};
    System.assert(mySet.size()==2,’Set size: ‘+mySet.size());
    }

    static testMethod void setTest(){

    Set<String> mySet = new Set<String> {‘a’, ‘A’};

    System.assert(mySet.size()==2,’Set size: ‘+mySet.size());

    }

    Similarly the key of a map is case-sensitive. At times this can be helpful, at other times irritating as most of the platform doesn’t care about case e.g. were you looking to find distinct lastnames in Contacts and you wanted to ignore case, one method would be to put all lastnames into a set. To ensure that different cases of the same lastname are considered equal you would have to lastname.toUpperCase() (or .toLowerCase()) before assigning the value to the set.

  • VisualForce component Ids when used in a rerender attribute. This one took me ages to figure out when I was a n00b. My rerenders would work with some components but not with others and I was befuddled until I realised I was being L-to-the-AME. My guess is that this area is case-sensitive becuase there’s some JavaScript going down in the background. For example

    <apex:outputPanel id=”thePanel“>

    <apex:commandbutton value=”Partial Page Refresh” action=”{!}” reRender=”thepanel“/>

    </apex:outputPanel>

    The rerender will not work because ‘thePanel’ is not regarded to be the same as ‘thepanel’. Go figure.

  • Salesforce 15 character Ids. This one is curtsy of David15 character IDs are case-sensitive, but 18-character IDs are case-insensitive. There is an algorithm for changing between the two, but the easiest way to do this is to use the FIXID() formula in the Excel Connector.
  • Most String methods. This is one area where case-sensitivity makes complete sense(If this doesn’t make complete sense to you drop me an email). More information on String methods can be found in the Salesforce Documentation.

As may or may not be apparent from the tone of this article, this area of the platform has been a source of life lessons(mostly in patience) for me. Once familiar with these(let’s call them) idiosyncrasies you’ll find a pace of development that is unprecedented on other platforms.

6 thoughts on “Force.com & Case-Sensitivity”

  1. Great post. A tweak, however:
    15 character IDs are case-sensitive, but 18-character IDs are case-insensitive. So the example you provided (with the EAY suffix) is actually case-insensitive. There is an algorithm for changing between the two, but the easiest way to do this is to use the FIXID() formula in the Excel Connector.
    Great blog! Keep up the good posts!

    Reply
  2. The names in a Custom Setting are case sensitive. If your case is wrong, your
    CustomSetting.getInstance(‘setting_name’) won’t. If it’s SEtTinG_NAmE, it has to stay SEtTinG_NAmE.

    Reply
  3. while comparing any String in IF, String will be Case-sensetive. eg. IF(account.nickName == ‘boss baby’, ‘Boss’,’Baby’) then account.nickName has to be ‘boss baby’ for the output to be Boss, if its ‘BoSs BaBy’ or any other combination of upper lower letters then output will be Baby.

    Reply

Leave a Comment