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
Rain.Rain. 

Update long-text field via Apex. Possible?

Hi all!

Question is, is it possible to write a trigger to update a long-text field with data while always keeping the previous data in it as well?

In more detail - whenever a custom-object record is created, then it would update the record related Account text-field with the name, while keeping all the previous names in that field. 
So the field on Account would look like this : Name1, Name2, Name3. 

Thanks!
Best Answer chosen by Rain.
James LoghryJames Loghry
Yes, it is possible.  Updating a long text field is no different than updating any other text field.

All Answers

James LoghryJames Loghry
Yes, it is possible.  Updating a long text field is no different than updating any other text field.
This was selected as the best answer
Rain.Rain.
Hi, thanks for the reply!

Just wondering, will I run into any sort of limits when there are more than 100k of such records created that will update their Account field?
Or is it something that can be worked through via Lists/Maps? 
James LoghryJames Loghry
You're only allowed to update up to 10,000 records per a single transaction according to governor limits.  Depending on how your trigger / field update is setup this may or may not be feasible.  However, you could kick off a batch job, which is more than capable of updating 100,000 records.  I would be leery though of the size of your long text area, as the "children" maybe too much for the long text area in some or several cases.  Why isn't a related list sufficient?
Rain.Rain.
Hi

The reason for this quite dirty workaround is reporting functionality.

We have custom object 'Purchases'.
Accounts that can have many of such records.

Now there is additional custom object 'Mailings Sent'.
Accounts can also have many of these.

Marketing people want to report on Mailings Sent, Purchases and Account data even though two these are not related, aside from that one Account in the middle.


Unable create a custom report type that includes data from all 3.

So as long as we'd even have this 'Mailings Sent' name on Account record, they would be happy.

// Also thank you for the batch-job idea. Will look into it.