How to add new line in Long Text Area field using Apex in Salesforce?

\n is used to add new line in Long Text Area field using Apex in Salesforce.

Sample Code:


  1. trigger AccountTrigger on Account ( before update ) {  
  2.   
  3.     for ( Account acc : trigger.new ) {  
  4.       
  5.         if ( acc.CustomerPriority__c != trigger.oldMap.get(acc.Id).CustomerPriority__c ) {  
  6.           
  7.             if  ( acc.Long__c == null )  
  8.                 acc.Long__c = 'Changed Customer Priority from ' + trigger.oldMap.get(acc.Id).CustomerPriority__c + ' to ' + acc.CustomerPriority__c + ' on ' + system.now();   
  9.             else   
  10.                 acc.Long__c = acc.Long__c + '\n Changed Customer Priority from ' + trigger.oldMap.get(acc.Id).CustomerPriority__c + ' to ' + acc.CustomerPriority__c + ' on ' + system.now();  
  11.              
  12.         }  
  13.               
  14.     }  
  15.       
  16. }  

Output:


No comments:

Post a Comment