Is there any reason why the apex:outputField in a visualforce page rendered as a PDF would not be formatting the phone numbers?

<apex:outputPanel rendered="{! generalContact.Phone_Field__c== '' }">
<apex:outputPanel rendered="{! generalContact.Phone_Field__c!= '' }">
     <apex:outputField value="{! generalContact.Phone_Field__c}"/>

Phone number in Lightning view

enter image description here

Phone number in PDF view. Disregard the differences in label; I was required to give the label name 'Work Phone' and, for posting purposes, I put an arbitrary phone name as a stand in for the actual field name. I'm referencing the same field, so this is not the issue at hand. Formatting is.

enter image description here

I am also unable to format the field like an outputText with params since it is not a number/date/time/choice field.

  • 2
    What's the actual value in the database? I believe Lightning formats the data after loading, while visualforce would not... – sfdcfox Nov 1 '19 at 20:31
  • It is being stored as 5555555555 according to workbench. I did some reading over how the numbers are stored, and it seems as though it depends on the criteria, although, with the given numbers, that does not appear to be true. help.salesforce.com/… – JRiffe Nov 1 '19 at 20:52

If you use the UI, and your locale is set, and the criteria is met, then the client performs phone formatting. The database does not perform any formatting, and some mobile apps do not, either. In Visualforce, no additional formatting is performed in Visualforce. Lightning, by contrast, will perform some automatic formatting in some cases (see lightning:formattedPhone). If your numbers are not formatted, Visualforce and Classic UI will not perform any formatting when displaying value. This is all expected behavior.

  • How can I format the phone if I can't with outputText and not have to do a wrapper class? – JRiffe Nov 4 '19 at 14:10
  • @JRiffe you can do so with apex:outputText or by formatting the field using an Apex controller. No wrapper is necessary. – sfdcfox Nov 4 '19 at 14:45
  • I tried and outputText and it gave me an error that only text, number, date, time, choice can be used in outputText. That was my first go to. This number is in a list of contacts, so there could be multiple so I can't directly convert it and store it in the controller as a string variable. Unless I'm just completely missing the point. – JRiffe Nov 4 '19 at 15:43
  • Also, I thought this was the purpose for using an outputField. – JRiffe Nov 4 '19 at 16:19
  • Nevermind.. I fixed it with outputText and MID functions. – JRiffe Nov 4 '19 at 16:47

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.