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

Is it possible to create a trigger to update Parent field in comma separated format???

I have two objects Deal(Parent) and Product(Child). I want to take all the product names which are associated with one Dealand Update it into Deal Object in comma separated format.


I know we can do this using VF and Apex. Can you please clarify is it possible through Triggers? And if yes please suggest some solution.


you can run a relationship query and get it done!


List<Deal> dealList = [select id,(select id from product_child_relationship_name) from deal];

For(Deal d : dealList){

List<Product> prodList = d.product_child_relationship_name;

Integer noOfProd = prodList.size();

d.CustomField = noOfProd;





this is posible through Triggers, use relationship query to get the total no. of child records and then use Join method of salesforce String methods so that you can concatente all the values and then store it on a Text field on Parent object.


Sample code for join method is as follows:-


List<Integer> li = new
{10, 20, 30};
String s = String.join(
li, '/');
'10/20/30', s);