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
Jacek DJacek D 

Using a trigger to do HTML field update?



I've been working in Salesforce for 4 months now and figured that Apex is a much more elegant way to solve some issues I ran into. Being relatively clueless about coding, but curious and open-minded, I am hoping you guys can help me.


I ran into this issue while populating a child object: The child needs to display the content of a HTML field of its parents. While text only can be done with a field update, the parent also includes a graphic. Is that possible?


And if so, how can I trigger field updates across objects with Apex (meaning, how do I create a link to a different object)?






The graphic in an HTML field will just be an HTML img component I'd imagine, so as long as the field on the child object is also an HTML field you should just be able to copy it.


With regard to the second part of your post,  if you have a child object in your code, it will have a lookup relationship to its parent, so you can use that to retrieve the parent.


Below is a quick example using a contact (child) to retrieve its parent (account);



Contact cont;
Account acc;

... set up cont here ...

List<Account> accs=[select id, Name from Account where id=:cont.AccountId];

if (!accs.isEmpty())