1

For this trigger:

trigger CompileQuickNotes on Contact (before update) {
    for( Id accountId : Trigger.newMap.keySet() )
    {
        if( Trigger.oldMap.get( accountId ).Log_Notes__c != Trigger.newMap.get( accountId ).Log_Notes__c )
        {
            Contact c = Trigger.newMap.get(accountId);

            //add information into quick notes field (with time stamp)
            String note = c.Log_Notes__c;
            String log = c.Quick_Notes__c == null ? '' : c.Quick_Notes__c;
            c.Quick_Notes__c = log + '[' + DateTime.now() +']: ' + note + '\n';

            //clear log notes field
            c.Log_Notes__c = '';

        }
    }
}

New lines do not seem to register on the Contact Page. I read alot of solutions of how to do it within visual force, but I wanted to know if there is a solution for pure apex trigger and the Contact page. I've tried all the suggestions pertaining to visualforce with no avail.

2
  • 1
    Is it just the new line that doesn't appear, or doesn't it save any log message? Salesforce will strip trailing new lines from text fields, which may explain your missing new line character. (That would be easy to fix by starting the message on a new line instead of ending it with a new line.)
    – Kasper
    Commented Jan 17, 2020 at 17:38
  • ah you are right it just stripped the trailing new lines! thanks.
    – Peabrain
    Commented Jan 17, 2020 at 17:41

1 Answer 1

0

Salesforce will strip trailing new lines from text fields, That would be easy to fix by starting the message on a new line instead of ending it with a new line.

Simply replace:

c.Quick_Notes__c = log + '[' + DateTime.now() +']: ' + note + '\n';

With:

c.Quick_Notes__c = log + '\n[' + DateTime.now() +']: ' + note;

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .