Tag Archives: New Line

Line Break in Apex PageMessage

You can add \n for HTML NewLine character in Apex String, and you can replace each \n by <br/> in apex:pageMessage using JSENCODE function.

Apex Controller:

public class SFController{  
    public String msg {get;set;}
    public SFController(){  
        msg = 'Error Message 1' + '\n' + 'Error Message 2' + '\n' + 'Error Message 3';  
    }  
}

Visualforce Page:

<apex:page controller="SFController">
    <apex:pageMessage summary="{!SUBSTITUTE(JSENCODE(msg), '\\n', '<br/>')}" severity="Error" strength="3" escape="false" />
</apex:page>

Output: