2

I've looked through various questions but still haven't found an answer. I have 5 fields that I can display on a VF pdf page and want each one on a different line, but if the IF fails, I don't want a blank line, so can't just put a br at the end. It needs to be inside the IF success part where I currently have & ' '. Please help!

            {!IF(activity.CallCycleActivity.Account__r.DementiaBeds__c > 0,'Dementia beds: ' & TEXT(activity.CallCycleActivity.Account__r.DementiaBeds__c) & '  ','')} 
            {!IF(activity.CallCycleActivity.Account__r.HospitalBeds__c > 0,'Hospital beds: ' & TEXT(activity.CallCycleActivity.Account__r.HospitalBeds__c) & '  ','')} 
            {!IF(activity.CallCycleActivity.Account__r.VillageBeds__c > 0,'Village beds: ' & TEXT(activity.CallCycleActivity.Account__r.VillageBeds__c),'')}

enter image description here

EDIT (from comments)

If I add:

& 'BR()'

it just displays it as

Dementia beds: 20 BR() Hospital beds: 42 Rest Home beds: 26

If I don't put quotes around it:

& BR()

It displays like this:

Dementia beds: 20_BR_ENCODED_ Hospital beds: 42 Rest Home beds: 26

  • 1
    Just add a BR() inside the IF(...)? – Adrian Larson Aug 24 '16 at 21:56
  • That doesn't work - it just displays it as "Dementia beds: 20 BR() Hospital beds: 42 Rest Home beds: 26 " if I include it in quotes, or like this "Dementia beds: 20_BR_ENCODED_ Hospital beds: 42 Rest Home beds: 26" if I don't put quotes around it. – Irene Aug 24 '16 at 22:33
  • Just edited my comment Adrian to explain both... – Irene Aug 24 '16 at 22:36
  • On the VF page you will have to use escape="false" if you are going to use BR() and are using outputText – Eric Aug 24 '16 at 23:15
4

Rather than trying to do everything in a large formula you can break it up into several controls.

Before:

<apex:page renderAs="PDF" standardController="Account">

    {!IF(Account.AnnualRevenue > 10,'More than 10: ' & TEXT(Account.AnnualRevenue) & BR() & '  ','')}&nbsp;
    {!IF(Account.AnnualRevenue > 20,'More than 20: ' & TEXT(Account.AnnualRevenue) & BR() & '  ','')}&nbsp;
    {!IF(Account.AnnualRevenue > 30,'More than 30: ' & TEXT(Account.AnnualRevenue) & '  ','')}

</apex:page>

After:

<apex:page renderAs="PDF" standardController="Account">

    <apex:outputText rendered="{!Account.AnnualRevenue > 10}" >More than 10: {!Account.AnnualRevenue}<br/></apex:outputText>
    <apex:outputText rendered="{!Account.AnnualRevenue > 20}" >More than 20: {!Account.AnnualRevenue}<br/></apex:outputText>
    <apex:outputText rendered="{!Account.AnnualRevenue > 30}" >More than 30: {!Account.AnnualRevenue}<br/></apex:outputText>

</apex:page>

Result:

Above the line shows the Before result and below the After result.

enter image description here

  • 2
    I prefer your way though as it doesn't use the "escape=false" (sorry @vorno) – Irene Aug 25 '16 at 0:25
3

Pop it into an outputText tag

<apex:outputText rendered="{!activity.CallCycleActivity.Account__r.DementiaBeds__c > 0}" value="Dementia beds: {!activity.CallCycleActivity.Account__r.DementiaBeds__c}<br/>" escape="false" />
<apex:outputText rendered="{!activity.CallCycleActivity.Account__r.HospitalBeds__c > 0}" value="Hospital beds: {!activity.CallCycleActivity.Account__r.HospitalBeds__c}<br/>" escape="false" />
<apex:outputText rendered="{!activity.CallCycleActivity.Account__r.VillageBeds__c  > 0}" value="Village beds: {!activity.CallCycleActivity.Account__r.VillageBeds__c}<br/>" escape="false" />
  • You don't need to add HTH to your posts. That's inherent in your attempt to answer, that you hope you are helping out. Welcome to SFSE! – Adrian Larson Aug 25 '16 at 0:10
  • 1
    Good manners don't cost nothing do they, eh – vorno Aug 25 '16 at 0:18
  • 1
    Similar issue to this meta post. It's irrelevant information. Just keep in mind it's a Q&A forum. Politeness is good but putting some sort of signature on every post is just overkill and would get old really quickly if everyone did it. – Adrian Larson Aug 25 '16 at 0:20

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.