The Silver Lining

Lessons & Learnings from a salesforce certified technical architect.

Force.com & Case-Sensitivity

with 5 comments

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.

Written by Wes

June 22, 2009 at 2:40 pm

5 Responses

Subscribe to comments with RSS.

  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!

    David

    June 24, 2009 at 2:24 am

    • Cheers mate. I’ve included your fix in the post.

      Wes

      June 24, 2009 at 12:58 pm

  2. Visualforce pages are also case-insensitive. ie. their name in a Force.com Site for example.

    Jon

    (Great blog Wes!)

    Jon Mountjoy

    June 29, 2009 at 8:21 am

  3. […] string you’re looking for. After figuring this out myself, I found a post about it over at The Silver Lining. Sure wish it were in the developer […]

  4. 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.

    Bing

    October 19, 2010 at 1:24 am


Leave a comment