1

I have a simple question that seems to be escaping me at the moment...

The typical way I use inline conditionals is: {!IF(booleanValue,"SOMECONTENT-IF VALUE IS TRUE", "SOMEOTHERCONTENT-IF VALUE IS FALSE")}

With the below conditional, how is it reading the second boolean value '00T'?

<apex:pageBlockTable value="{!list}" var="item">
    <apex:column headerValue="Created By">
        <apex:variable var="field" value="{!IF(BEGINS('00a', '00T'), 'Owner.Name', 'CreatedById')}" />
        <apex:outputField value="{!item[field]}" />
    </apex:column>
</apex:pageBlockTable>

UPDATE: I wasn't looking at the structure correctly. This is saying:

IF '00a' beings with '00T' then show Owner.Name. IF NOT show CreatedByID.

  • 2
    What exactly is your question? Right now your conditional just reads IF(false, ...)} which just ultimately simplifies to 'CreatedById'. – Adrian Larson Apr 18 '17 at 18:01
  • Updated question with more code. I assume it is saying if the 'item' begins with 00a then... – Olivia Apr 18 '17 at 18:11
  • No, it's just checking if '00a' begins with '00T', which is always false. Perhaps '00a' was meant to be item.Id, but it's hard to tell. – Adrian Larson Apr 18 '17 at 18:12
1

BEGINS('00a', '00T') always returns false, as it will try to search 00T within 00a

Put your logic properly like this:

<apex:pageBlockTable value="{!list}" var="item">
    <apex:column headerValue="Created By">
        <apex:variable var="field" value="{!IF(BEGINS(<field To Compare>, <value to compare>), Owner.Name, CreatedById)}" />
        <apex:outputField value="{!item[field]}" />
    </apex:column>
</apex:pageBlockTable>
  • @santau thank you! I had a brain lapse. Both of you guys are correct, I updated my question with the right answer – Olivia Apr 18 '17 at 18:17
1

What the formula you have is actually checking is if the string '00a' begins with the string '00T', which is always false. So you could replace the current merge field in its entirety with {!'CreatedById'}.

A more likely intent would be if list has a mixed collection of SObject records, and you're not sure of the type. In that case, you might want to check if the record is a Task (Id begins with '00T') or some custom object (Id begins with '00a'). If that's the case, your formula would look more like:

IF(BEGINS(item.Id, '00T', 'Owner.Id', 'CreatedById'))

Depends on how many object types you have to handle, how exactly you would proceed. But that's the idea.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.