3

I have a list of account bound to a apex:pageblocktable. I need a way of displaying just the first 100 chars of the field description on the table.

<apex:column headerValue="{!$ObjectType.Account.Fields.Description.Label}">
       <apex:outputField value="{!s.Description}"   />
</apex:column>

Tried changing it to

<apex:column headerValue="{!$ObjectType.Account.Fields.Description.Label}">
                    <apex:outputText value="{!if(String.IsBlank(s.Description),'',s.Description.left(100))}"   />
                </apex:column>

But throws

Error: Unknown function String.IsBlank. Check spelling

Any other way we can achieve this?

  • 1
    LEFT? help.salesforce.com/apex/… – eyescream May 29 '13 at 10:57
  • If you're looking to take up "all available space, but no more", consider using slds-truncate if you're using slds, or text-overflow: ellipsis; white-space: nowrap; overflow: hidden otherwise. This looks nicer from a UX perspective. – sfdcfox Sep 27 '17 at 17:25
5

there is a simple way to do this

<apex:outputText value="{!left(Account.description,100)}"   />
|improve this answer|||||
  • Thanks Doug, if description returns a null, wouldnt it throw exception? – Prady May 29 '13 at 11:04
  • No, it will not throw an exception. The VF functions are more tolerant than the Apex string functions. You can check it out for yourself, it will work fine with null. – Doug B May 29 '13 at 11:18
  • Awesome... works like charm – Prady May 29 '13 at 11:40
1

I add the following to add an ellipsis if the string gets truncated.

<apex:outputText value="{!IF(LEN(Account.description) > 100, LEFT(Account.description, 97) + '...', Account.description)}  />
|improve this answer|||||

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.