Pages

Saturday, February 11, 2012

Don't Double Quote Me!

I came across an odd bug within a Visualforce page yesterday.  At least I think it is a bug - I can't explain it and it has been esclated to an upper tier of premier support.

Within an <apex:outputPanel />, I was using a "rendered" formula within the tag:

<apex:outputPanel rendered="{!If(AND(myObject__c.relatedObject__r.theSuspectField__c = 'The Picklist Value',myObject__c.myField2 > 0), true,false)}">


Ater I saved the page (and although the page would save), I started to receive warnings that I needed to close my tag. Thinking that was strange, I commented out everything between my and tags and received the same thing. Then I saw my rendered formula - that's strange, I must have used double quotes by accident. This is what I saw:

<apex:outputPanel rendered="{!If(AND(myObject__c.relatedObject__r.theSuspectField__c = "The Picklist Value",myObject__c.myField2 > 0), true,false)}">


I replaced the double quotes with single ticks again, hit save, and bam - they were converted to doubles again.

What gives?

Eventually I figured out that if I changed the order in which my fields were listed, the record would save as expected - no double quotes:

<apex:outputPanel rendered="{!If(AND(myObject__c.myField2 > 0,myObject__c.relatedObject__r.theSuspectField__c = 'The Picklist Value'), true,false)}">


I'm assuming that this it has something to do with myObject__c.relatedObject__r.theSuspectField__c being a picklist field, located on a related record.  Why it works in an alternate position in the formula, beats me, but is probably one of those strang quirks of Salesforce.

I'll update as I find out more.

Note:  I was using the inline VF editor, but saw the same issue when I attempted to resolve the issue within the Force.com/Eclipse IDE.