It seems like my rendered If statement is not evaluating as expected (at least my expectations). Basically, I have 2 Id fields pulled from apex, and if they equal each other, it conditionally displays some outputText.

rendered="{!IF(nameMap[BillingName] == LP.Id, TRUE, FALSE)}"

Here is the VF page:

        <apex:repeat value="{!localPartners}" var="LP">
            <apex:pageBlockSection title="{!LP.Name}">
                <apex:repeat value="{!nameMap}" var="BillingName">
                    <apex:pageBlockSection title="{!BillingName}" columns="1"> 
                        LP ID: {!LP.Id}<br/>
                        Map ID: {!nameMap[BillingName]}<br/>
                        <apex:outputText rendered="{!IF(nameMap[BillingName] == LP.Id, TRUE, FALSE)}"> MATCHES </apex:outputText>
                        <apex:outputText rendered="{!IF(nameMap[BillingName] != LP.Id, TRUE, FALSE)}"> DOESN'T MATCH </apex:outputText>

I tried to troubleshoot my issue by printing both Ids on the page and the results of the If statement as shown in the two outputTexts. if LP Id == Map Id, it will show "MATCHES", and "DOESN'T MATCH" otherwise.

However, it seems like even when the Ids are an exact match, it never renders the True condition, as shown below in the red box:Id does not match.

Is there something incorrect with my VF syntax? Or is there some hidden whitespace? I am certain they are both Ids.

public List<Account> localPartners {get;set;}
public Map<String, Id> nameMap {get;set;}


  • 1
    do you have any action function in the vf page? – night crawler Oct 17 '17 at 6:52
  • 1
    Interesting! Couple ideas: 1) What happens when you simplify? Remove the if, use only rendered="{!nameMap[BillingName] = LP.Id}". 2) Try wrapping both values with CASESAFEID() or maybe LOWER() both values. I have a feeling one of id's becomes 15-char long and then it fails string comparison. help.salesforce.com/… – eyescream Oct 17 '17 at 7:55
  • @nightcrawler I did have two action functions, one on the main <apex:page> and another rerender on a button, but I stripped everything to troubleshoot this problem. – PrawnCrackers Oct 19 '17 at 23:17
  • @eyescream I didn't get a chance to try CASESAFEID() as I just avoided the problem altogether by not accessing the var's Id. I redid my entire Controller so now all the if statements compare vars only, e.g. {!IF(InvoiceBilling1 == BillingName, True, False)}. I will definitely keep that in mind for next time. It is strange how both Ids case and length are exactly the same on the page but they might not be those values. Thanks for your help :) – PrawnCrackers Oct 19 '17 at 23:35
  • Feel free to add it as your own answer, I'd happily upvote it :) Congrats on solving the mystery (well, finding a valid workaround)! – eyescream Oct 20 '17 at 4:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.