Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7778449
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T18:24:00+00:00 2026-06-01T18:24:00+00:00

I have a custom field called Current_Address__c which is of datatype textarea. I need

  • 0

I have a custom field called Current_Address__c which is of datatype textarea.

I need to populate this field in the format below. ie a newline char after street and another newline after zip.

street
City state Zip
Country

The values of city state zip country etc are been taken from contact object. I dont want to use this as a formula field. So i need to populate it in my controller and display it on my VF page.

I am trying to add a newline char by using the code below

this.customobj.Current_Address__c = currentStreet + '\\n ' + currentCity + ' ' + currentState  + ' ' + currentZIP  + '\\n ' + currentCountry ;

i had also used \n instead of \n.

It still show the field in one line instead of 3 lines

EDIT

I got this working using the following code. I would accept mathews answer as it would work with outputfield.

                currentAddress = currentStreet;
            currentAddress += '\r\n';
            currentAddress += currentCity + + ' ' + currentState  + ' ' + currentZIP ;
            currentAddress += '\r\n';
            currentAddress += currentCountry;

This works only if you use +=.
not sure why this happens

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T18:24:02+00:00Added an answer on June 1, 2026 at 6:24 pm

    I think I found the issue, you have two escape character slashes (\\n), but only one is needed because the slash in \n does not need to be escaped in this context.

    Also, Salesforce saves a new line as \r\n. Try this:

    this.customobj.Current_Address__c 
        = currentStreet + ' \r\n' 
        + currentCity + ' ' + currentState  + ' ' + currentZIP  + ' \r\n' 
        + currentCountry;
    

    This method works when using an <apex:outputfield> with an sObject field.

    <apex:outputtext value="{!myCustomSObject__c.Address__c}"/>
    

    If you’re using a different Visualforce Component, it won’t work. Visualforce renders the new line in HTML when using a <apex:outputtext> Component, but HTML ignores new lines. If you use a <br/> tag, Visualforce renders it as &lt;br/&gt;.

    The best solution I could come up with for rendering a variable that has new lines in it (rather than an sObject field) is to use a disabled <apex:inputtextarea>.

    <apex:inputtextarea value="{!myAddress}" disabled="true" readonly="true">
    </apex:inputtextarea>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom field called HourField, which lets you enter 1:30 to represent
I have a custom field in WordPress called thumb-url which contains the exact location
I have a custom content type which has a field called location which is
I have a TFS 2010 Work Item Type with a custom field called Requested
In my SharePoint List I have a custom field which is a filtered lookup.
I have a custom list_display field which is responsible for a column of integers
I have a multiple pages in wordpress all with a single custom field called
I have a phpBB installation. I've added custom profile field called 'insurance number'. Every
I have a custom UserType which stores a date/time value in a TIMESTAMP field
I have a custom content type that has a custom field called [stock] I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.