Groovy 38 – Create M:M Relationship in Groovy

I have created a custom object called Campaign_c and then created a M:M relationship with Contact object.

The intersection object I called it CampIntCont

  • ObjectA is the Source Object: Campaign
  • ObjectB is the Intersection Object : CampIntCont
  • ObjectC is the Target Object: Person

-Field name for the foreign key to the Source Object: ObjectA_Id_Src_ObjectAToObjectB_c


-Field name for the foreign key to the Target Object: ObjectC_Id_Tgt_ObjectCToObjectB_c


You have I also created a DCL as a picker for contacts to be added  in the custom Object Campaign

I called it: ContactPicker_c

Now Create a Trigger Before Update (to add on update record the contact) or Create a Action Link in Custom object Campaign

Same script works in both situations.

Script looks like this:

 //here I am getting the party Id of the contact to 
 //be added from the DCL(you did not specified how contacts are picked up so I improvised)  
def partyId = ContactPicker_Id_c 
def addContact = newView(‘CampIntCont_c’)  
def addRow = addContact.createRow()  

Leave a Reply

Your email address will not be published. Required fields are marked *