function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tdeptdep 

Help with a Trigger that Compiles related records into 1 text field (working)

I have a trigger that compiles a related object (US_Comments__c) up to the parent record (US_Projects__c).
Everything works fine but I have to populate the CommentCompilation__c field initially which has resulted in an annoying little . at the beginning on each compilation.
Part giving me an issue:
a.CommentCompilation__c = '.';
I have tried to initiate the value as null, '', "", etc. and nothing works. Anyone have a tip on how to initiate it and then possibly remove that entry? or a value that will display as blank?

here is the full trigger for reference:
trigger CommentCompilationUSProject on US_Project__c (before update) {

for(US_Project__c a:[select id,
                             (select id,Name,Source__c,Comments__c from US_Comments__r ORDER BY CreatedDate DESC)
                                from US_Project__c where id in :trigger.new]) 
{    
    a.CommentCompilation__c = '.';
    
    for(US_Comments__c o:a.US_Comments__r)
     
    a.CommentCompilation__c += ' \n ' + o.Name + ' - ' + o.Source__c + ' - ' + o.Comments__c + ' \n ';
    //String.valueOf(o.Comments__c)
    Trigger.newMap.get(a.id).CommentCompilation__c = a.CommentCompilation__c;
  }
  
}
 

 Thanks in advance!

dmchengdmcheng

have you tried using a separate string variable for the concatenation?