I think I found the problem, you have two escape-character slashes ( \\n
), but only one is needed, because in this context no slash is needed in \n
.
In addition, Salesforce saves the new line as \r\n
. Try the following:
this.customobj.Current_Address__c = currentStreet + ' \r\n' + currentCity + ' ' + currentState + ' ' + currentZIP + ' \r\n' + currentCountry;
This method works when using <apex:outputfield>
with the sObject field.
<apex:outputtext value="{!myCustomSObject__c.Address__c}"/>
If you use another component of Visualforce, this will not work. Visualforce displays a newline in HTML when using the <apex:outputtext>
component, but HTML ignores newlines. If you use the <br/>
tag, Visualforce displays it as <br/>
.
The best solution I could offer for rendering a variable with new lines in it (and not with the sObject field) is to use the disabled <apex:inputtextarea>
.
<apex:inputtextarea value="{!myAddress}" disabled="true" readonly="true"> </apex:inputtextarea>
source share