I've got a custom JS button on a custom object call Card, and the Card object is child to Contract (via Lookup). That JS button (called New Adult Card) shows up on the Cards related list on the Contract page layout (i.e. I have access to Contract merge fields in the button. So when I do {!Contract.Account}, that let's me reference the standard Account lookup on the Contract object. All out of the box, that works fine... except what if that Account has a special character in it? JSENCODE to the rescue, right?
Wrong, {!JSENCODE(Contract.Account)} returns the Id of the Account record. Huh?
JSINHTMLENCODE() and URLENCODE() both work in exactly the same way.
{!JSENCODE(Contract.Account.Name)} doesn't even save, throws an invalid field error.
I worked around it with the following, which is fine, but I'd like to understand the observed behavior mentioned above. Anyone have any bright ideas?
var acctName = "{!Contract.Account}";<br/>
alert(acctName);<br/>
var acctNameEncode = encodeURIComponent(acctName);<br/>
alert (acctNameEncode);