function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
StrangeRoutinesStrangeRoutines 

Use of RecordType in a URL formula for a custom button

I want to open a VisualForce page based on the value of a RecordType in a custom object. For maintainability, it seemed like the easiest thing was to map the RecordType string to the page name by drop illegal characters like ampersands, etc.  For instance, if the RecordType was "Flood/Fire Damage" then the page name would be "floodfiredamage". So I coded a URL for a custom detail button like this (the custom object is Quote__c):

 

/apex/{!CASE(Quote__c.RecortType,"Flood/Fire Damage","FloodFireDamage","")}?ID={!Quote__c.Id}

 

(In the real situation, there would be many value/result pairs in the CASE statement, only one is shown here for simplicity.) To my surprise it did not work. After flailing around for a long while I coded up the following URL and VFpage to demonstrate the problem (I am using the UPPER function as a simple example for calling a function with a RecordType):

 

URL on custom button:

/apex/testpage?ID={!Quote__c.Id}&param1={!Quote__c.RecordType}&param2={!UPPER( Quote__c.RecordType)}

 

VFpage TestPage contents:

<apex:page standardController="Quote__c">
<p>id={!$Currentpage.parameters.id}</p>
<p>param1={!$Currentpage.parameters.param1}</p>
<p>param2={!$Currentpage.parameters.param2}</p>
</apex:page>

 

And here is the result when I click the button to invoke TestPage:

id=a0750000005PHAf
param1=Employers Liability
param2=01250000000QHEY

 

So, why is it when I use RecordType straight out I get the value but I put it inside a function I get the internal id? And, how do I get around it? Currently, I'm contemplating putting a field in the custom object itself that does the mapping from RecordType name to destination page name and then using that field in the URL but that seems inelegant. (Of course, a a big ugly CASE statement isn't all that elegant either!)

 

Thanks!