Use of \n in Apex

 Use of  \n in Apex :


Example 1:

<apex:page controller="myClass">   

<apex:outputLabel value="{!SUBSTITUTE(JSENCODE(myText), '\\n', '<br/>')}" escape="false"/ >   

</apex:page>  


 public class myClass{  

   public String myText{get;set;}  

   public myClass(){  

      myText = 'Testing Header' + '\n' + ' Testing Content.' + '\n' + 'Testing Footer';  

   }  

 }


Example 2:

trigger myTrigger on Account (before update) {  

for(Account acct : trigger.new){  

if (acct.myField__c != trigger.oldMap.get(acct.Id).myField__c) {  

if  (acct.otherField__c == null)  

acct.otherField__c = 'Testing ' + trigger.oldMap.get(acct.Id).myField__c + ' of ' + acct.myField__c + ' on ' + system.now();   

else   

acct.otherField__c = acct.otherField__c + '\n Testing ' + trigger.oldMap.get(acc.Id).myField__c + ' of ' + acct.myField__c + ' on ' + system.now();  

}  

}  

}  

 

Comments