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
yervandyyervandy 

Accessing related list and inserting in text area

I would like help on writing a trigger on Account before update that gets the related contacts, then inserts that list of contacts in an account text area field.

 

The text area will contain:

contact name 1\n

contact name 2\n

etc...

 

I'm not an apex developer so I'm not sure where to begin, so any sample code for doing something like that would be a great help.

 

Thanks.

wAndwAnd
trigger AccountTrigger on Account( before update, before insert ){  
  List<Account> accounts = Trigger.new;
  //get your contacts and operate on each account
  for( Account acc : accounts ){
    acc.someField = contacts;
  }
}

 I'm not sure whether the text area field can be inserted manually, because the line feed and '<br>' will be escaped.

yervandyyervandy

Thanks for the reply. How can this be done with a custom object? My Case object has a child object Case_Update__c. I would like to have that list of updates associated with the case to be written to a text area on a case. Here are the steps.

 

trigger CaseUpdateList on Case (before update) {
   List<Case_Update__c> cu [select id, description__c from Case_Update__c
   where Case__r.id in :Trigger.new];
 
   \\the following is pseudocode
   Loop through each cu List item {
      Case.All_Updates__c = Case.All_Updates__c + cu.description__c;
   }
}

 

 

I hope that makes sense. I've been struggling a lot with this.

 

And thanks again.