Find your content:

Search form

You are here

Hash symbol when binding variables in URL


I'm trying to populate the Contact lookup when a User creates a new related list object from the Contact page.

I am storing the Contact parameter in a Custom Setting so it can be changed when deploying to Production.

For some reason, whenever I try to bind this custom setting to the URL I get a leading '#' and none of the bindings work correctly. This is despite using the URLENCODE function in the Visualforce

So when I put this (contactParameterId is != null)

<apex:outputLink value="/{!relList.keyPrefixObject}/e?{!IF(relList.contactParameterId != null, 'CF{!URLENCODE(relList.contactParameterId)}={!URLENCODE(contact.Id)}&', '')}retURL=/{!contact.Id}&saveURL=/{!contact.Id}"></apex:outputLink>

I get the URL{URLENCODE(relList.contactParameterId)}={!URLENCODE(contact.Id)}&retURL=/003U000000PL9LNIA1&saveURL=/003U000000PL9LNIA1

What am I doing wrong?

Attribution to: George S.

Possible Suggestion/Solution #1

EDIT: You already are in the "merge fields syntax" with the {!IF ... }. There's no need to use { ... } again inside this IF but you have 'CF{!URLENCODE...

So probably something like this will be better:

    value="/{!relList.keyPrefixObject}/e?{!IF(relList.contactParameterId != null, 'CF' & URLENCODE(relList.contactParameterId) & '=' & URLENCODE(contact.Id),'')}&retURL=/{!contact.Id}&saveURL=/{!contact.Id}">

(you probably also don't need to URLENCODE anything here, both field Ids and record Ids should be "safe")

I don't think you're doing anything wrong.

Server-side parser gets in my opinion stupid overzealous with URLENCODE'ing too much stuff you'd consider safe. Might be even related to my question Proper urlencoding of spaces in formulas syntax

I have a massive <apex:commandButton /> to redirect user from my overridden VF page to standard edit page while salvaging what I can (prepopulating some fields) if he needs to fall back to original behavior of the page.

<apex:commandButton value="classic 'new' page"
    action="{!URLFOR($Action.Purchase_Order_Item__c.New, $ObjectType.Purchase_Order_Item__c, 
        [retURL=URLFOR($Action.Purchase_Order__c.View, po.Id),
        saveURL=URLFOR($Action.Purchase_Order__c.View, po.Id),
        true) + '&00ND0000003F2Gw=' + po.PO_Type__c + '&00ND0000003F2Gv=' + po.PO_Sub_Type__c}"
    rendered="{! = ''}" />

po is the "Purchase Order" header and this button sits on the page we use to create new line items.

As you can see this abomination deals with your "CF" problem outside of URLFOR. Additionally fields with names that begin with 0 will prevent you from saving the VF page so I had to put them outside of the URLFOR too (they're picklists if that's relevant).

Attribution to: eyescream
This content is remixed from stackoverflow or stackexchange. Please visit

My Block Status

My Block Content