\n is used to add new line in Long Text Area field using Apex in Salesforce.
Sample Code:
Output:
Sample Code:
- trigger AccountTrigger on Account ( before update ) {
- for ( Account acc : trigger.new ) {
- if ( acc.CustomerPriority__c != trigger.oldMap.get(acc.Id).CustomerPriority__c ) {
- if ( acc.Long__c == null )
- acc.Long__c = 'Changed Customer Priority from ' + trigger.oldMap.get(acc.Id).CustomerPriority__c + ' to ' + acc.CustomerPriority__c + ' on ' + system.now();
- else
- 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();
- }
- }
- }
Output:
how to insert line break to long text area field from api.. I have tried \n, \r\n but nothing works.. Please help!
ReplyDeleteDon't use \n or \r from the API.
DeleteUse String.escapeSingleQuotes() in Apex before the field update in the class.