Oh my god. It's full of code!

Posts tagged “expand

Coldfusion Expand Salesforce object Id

Hey all.
Just another quick handy ColdFusion function here. This one will allow you to take a fifteen char Salesforce ID, and expand it into an eighteen character one. This is useful since if you want to store Salesforce Ids in ColdFusion, you’ll want a none case sensitive version, which is what the 18 character long one is good for. The 15 char one is case sensitive, while the 18 char one is not. So I always work with the 18 char one, since it’s easier.

<cffunction name="ExpandSFID" hint="I take a 15 char salesforce ID and turn it ino the 18 char one">
    <cfargument name="SFID" type="string" required="yes">
    <cfset var map = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ012345'>
    <cfset var = arraynew(1)>
        <cfif len(arguments.SFID) eq 15>
            <cfset ChunkTotal[1] = 0>
            <cfset ChunkTotal[2] = 0>
            <cfset ChunkTotal[3] = 0>
                <cfloop from="1" to="3" index="i"> 
                    <cfloop from="5" to="1" index="j" step="-1">
                        <cfset c = mid(arguments.sfid, ((i-1)*5)+j, 1)>
                        <cfif reFind("^[A-Z]$", c) GT 0>
                            <cfset ChunkTotal[i] += 2^(j-1)>
                        <cfset arguments.SFID &= mid(map,ChunkTotal[i]+1,1)>      
            <cfreturn arguments.SFID>
        <cfcatch type="any">
            <cfreturn "Error Converting Salesforce ID #cfcatch.message# #cfcatch.detail#">

Hope this helps!