• William Brown 29
  • NEWBIE
  • 0 Points
  • Member since 2022

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 0
    Questions
  • 1
    Replies
Hi All,
I am trying to update related record field values into parent record in a self lookup. I tried writing a triggrt for this but it is not working. This is my code.

 
trigger updComments on college__c (after insert, after update, after delete)
   Set<id> accIdList = new Set<id>();
    List<College__c> colllist = new List<College__c>();
   for(College__c con : Trigger.new)
   {
    accIdList.add(con.College__c);
   }
    for(College__c acc : [Select id, name, University__c,Comments__c,Combined_COmments__c, 
                             (Select Id, name,University__c,Comments__c,Combined_COmments__c From College__r) 
                        From College__c Where Id In : accIdList])
{
    List<String> lstSrting = new List<String>();
    for(College__c con : acc.University__c__r)
    {
        lstSrting.add(con.Comments__c);
    }
    College__c a = new College__c();
    a.id = acc.College__c;
    a.Combined_COmments__c = String.join(lstSrting, ',');
    colllist.add(a);
}
    update colllist;



In above code University__c is a self lookup, I am updaing Comments__c child values into Combined_COmments__c parent record.

Can anyone please suggest me where I am doing wrong
Thanks in Advance