+ Start a Discussion
Amn12345Amn12345 

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.

ibtesamibtesam

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;

}

Vinit_KumarVinit_Kumar

Yes,

 

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
List<Integer>
{10, 20, 30};
String s = String.join(
li, '/');
System.assertEquals(
'10/20/30', s);