[SalesForce] Formula Field with line break in visualforce

I have a formula field that determines our company address based on a region (custom field) on account:

IF(CONTAINS(TEXT(Account__r.Region__c),"US"),
"Company, Inc." & BR() &"A street" & BR() & "Suite 530" & BR() &"Boston, MA 02210",
IF(NOT(ISPICKVAL(Account__r.Region__c,"")),"Company, Ltd." & BR() & "B Street" & BR() & "5th Floor" & BR() & " UK", "Please update account region"))

When using this field in a standard layout, it appear ok. i.e.:

Company, Inc.
A street
Suite 530
Boston, MA 02210

I tried placing this field in a visualforce page using this format:

<apex:outputText value="{!Custom_Object__c.Company_Address__c}" escape="false"/>

and got this result:

Company, Inc.
27-43
A Street
Suite 530
Boston,
MA
02210

Any explination why the line break happens and how I can fix it?

<apex:page standardController="Monthly_Cloud_Bill__c" showHeader="false" renderas="pdf"> 

<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>
    <td align="left">       <img src='{!URLFOR($Resource.Logo)}' title="logo" />
     <br/>
     <img src='{!URLFOR($Resource.InvoiceLogo)}' title="logo" />
       </td>

       <td align="right" > <apex:outputText value="{!Monthly_Cloud_Bill__c.Company_Address__c}" escape="false"/>    
    </td>
</tr>



</table>

<br/>

<table border="0" cellspacing="0" cellpadding="0" width="100%" id="table1">
<tr>    <td>


        Invoice Date: {!Monthly_Cloud_Bill__c.Invoice_Created_Date__c} <br/>
        Invoice #: {!Monthly_Cloud_Bill__c.Invoice_Number__c}<br/> 
        Billing Period: {!Monthly_Cloud_Bill__c.Billing_Period__c}  <br/> 
        Customer ID: {!Monthly_Cloud_Bill__c.Account__r.Customer_ID__c} <br/>


        </td> 
        <td width="50%"></td>

</tr>
</table>

<p><b><font face="Arial" color="#000080">Customer Information</font></b></p>

<table border="0" width="100%" id="table2">
<tr>
       <td colspan="3">
           <font face="Arial">{!Monthly_Cloud_Bill__c.Account__r.Name} <br/></font>
       </td>
</tr>
<tr>
       <td>          
           <font face="Arial">Attn: {!Monthly_Cloud_Bill__c.Contact__r.Name}<br/>

                             {!Monthly_Cloud_Bill__c.Account__r.BillingStreet}<br/>
                             {!Monthly_Cloud_Bill__c.Account__r.BillingCity}, {!Monthly_Cloud_Bill__c.Account__r.BillingState} {!Monthly_Cloud_Bill__c.Account__r.BillingPostalCode} <br/>
                             {!Monthly_Cloud_Bill__c.Account__r.BillingCountry} <br/>
                             Tel: {!Monthly_Cloud_Bill__c.Contact__r.Name}
           </font>
        </td>

</tr>    
</table>

<p><b><font color="#000080" face="Arial">Order Description</font></b></p>
<table border="1" width="100%" id="table4">
<tr>
       <td bgcolor="#C0C0C0"><font face="Arial">Product</font></td>
       <td bgcolor="#C0C0C0" align="center"><font face="Arial">Price Per VM</font></td>
       <td bgcolor="#C0C0C0" align="center"><font face="Arial">Average # of VM's</font></td>       
       <td bgcolor="#C0C0C0" align="center"><font face="Arial">Amount</font></td> 
</tr>
<tr>

             <td>Product</td>
             <td align="center"> {!Monthly_Cloud_Bill__c.Effective_Price_Per_VM_Per_Month__c}</td>  
             <td align="center">{!Monthly_Cloud_Bill__c.Reported_Usage__c}</td>             
             <td align="center">{!Monthly_Cloud_Bill__c.Reported_Usage_Price_Per_Vm__c} </td>  
          </tr>

<tr style="display: {!IF(ISBLANK(Monthly_Cloud_Bill__c.Adjustments__c), 'none', 'table-row')};">

    <td align="left"> Adjustments </td>  
    <td>  
    </td> 
      <td  align="center"> {!Monthly_Cloud_Bill__c.Adjustments__c}   </td> 
      <td> 
      </td>

</tr>

<tr style="display: {!IF(ISBLANK(Monthly_Cloud_Bill__c.Adjustments__c), 'none', 'table-row')};">

    <td align="left"> Reported Trial Usage </td>  
  <td>
    </td> 
  <td  align="center"> {!Monthly_Cloud_Bill__c.Reported_Trial_Usage__c}   </td>
   <td>
    </td>

</tr>

<tr style="display: {!IF(ISBLANK(Monthly_Cloud_Bill__c.Adjustments__c), 'none', 'table-row')};">

    <td align="left"> Net Usage For Billing  </td>  
  <td align = "center">
  {!Monthly_Cloud_Bill__c.Effective_Price_Per_VM_Per_Month__c}
    </td> 
  <td  align="center"> {!Monthly_Cloud_Bill__c.Net_Usage_For_Billing__c}   </td>

   <td align="center">
   {!Monthly_Cloud_Bill__c.Billing_Amount__c}
    </td>

</tr>



<tr>
       <td bgcolor="#C0C0C0" align="right" colspan="6">
       <font face="Arial"><b>Total Due:</b><apex:OutputField value="{!Monthly_Cloud_Bill__c.Billing_Amount__c}"/></font></td>
</tr>
</table>

<p><b><font color="#000080" face="Arial">Payment Instructions</font></b></p>
<table border="0" width="100%" id="table3">
 <tr>
       <td><font face="Arial">

             1. Payment is due in full 30 days from the INVOICE DATE <br/>

            </font>
        </td>

   <br/>

</tr> 



<table border="0" width="100%" id="table4">
<!--<tr>
       <td colspan="3">

       </td>
</tr> -->
<tr>
       <td>          
           <font face="Arial"><b>Wire transfer instructions:</b><br/>

                           <apex:OutputField value="{!Monthly_Cloud_Bill__c.Wire_transfer_instructions__c}"/>
           </font>
        </td>
    <!--    <td width="1%"></td> -->

        <td>
           <font face="Arial"><b>Check payment instructions:</b><br/>
                            <apex:OutputField value="{!Monthly_Cloud_Bill__c.Check_payment_instructions__c}"/>
           </font>
        </td>



</tr>    
</table>

</table>

<hr/>
<p align="center"><font face="Arial">If you have any question about this invoice, please contact. <br/>
{!Monthly_Cloud_Bill__c.Account__r.Owner.FirstName} {!Monthly_Cloud_Bill__c.Account__r.Owner.LastName}, {!Monthly_Cloud_Bill__c.Account__r.Owner.Phone}, {!Monthly_Cloud_Bill__c.Account__r.Owner.Email} <br/> <br/>
<b>Thank You For Your Business!</b>
</font></p>

</apex:page>

Best Answer

You don't show us the format of the VF page you're putting this into, but I strongly suspect you're outputting this text into a table of some sort that isn't wide enough to allow everything to stay together. If you post the code for the page, we're much more likely to be able to provide more specific help. In general, my guess off-hand would be that you need to specify the min cell width in pixels for the column that you're displaying the company address in.

Your other option, would be to get each line of the company's address and output them one by one with a <br></br> between each of them. As in you'd need to get the company street address, followed by the City, then the State, zip, etc. Where possible, you'd also want to include a &nbsp between 27-43 (the street number) and the "A" along with "Street" as shown below if you want them all to stay together:

<p>27-43 &nbsp A &nbsp Street</p>

The above would keep all of the above on a single line. Any overflow would either be clipped or else flow into an adjacent column if the column was empty.

Related Topic