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.

  • 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 Jan 17 at 17:38
  • ah you are right it just stripped the trailing new lines! thanks. – Peabrain Jan 17 at 17:41
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;

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.