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
Shantanu Punekar 5Shantanu Punekar 5 

Trigger for creating junction object automatically.

Hello,

I have a requirement, where a junction object record needs to be created based on the matching field values of both the parent objects.
For e.g Master1 object (Flat) has a picklist field 'Flat type' (1BHK, 2BHK) and same field is there on Master2 object (Enquiry). If 'Flat type' picklist value matches in both Master object a new junction object record needs to be created with same both records as parent. 
i.e If a Enquiry record is created with 1BHK as Flat Type then it should match with some existing record in Flat object with 1BHK as flat type and then a new junction object record should be created.

I am new in development and have no idea where to start with.
Please help.

Thanks in advance.
 
Thiyagarajan Selvaraj (SFDC Developer)Thiyagarajan Selvaraj (SFDC Developer)
Hi Shantanu,

Create a trigger on both flat and Enquiry objects. On flat object trigger, match the flat field values with enquiry object records, if it matches create junction object records. Likewise, on enquiry object trigger, match the enquiry field values with flat object records, if it matches create junction object records.