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
Dea73Dea73 

Many to many relation ship junction object question----need help!!!

Hi,

 

I have an Object A that has a many to many relationship to Object B.

Because of this i have created junction Object C

I have created a wizard that makes it possible to select 3 object B.

 

In my controller extension I'm able to create a new instance of Object A along with the 3 selected instances of Object B correctly populated ( as lookup fields)

How do i retrieve the ids of the lookup fields to create 3 seperate instances of the junction object????

Pradeep_NavatarPradeep_Navatar

Find below a sample code :

 

                // Create a record in Object A -- RecA

                ObjectA__c objA = New ObjectA__c(Name='VKS__A');

 

                for(Integer i=0; i<3 ; i++)

                {

                                ObjectB__c objB = New ObjectB__c(Name='VKS__B',ObjectA_Lookup__c =:RecA.id);

                                insert objB;

                                ObjectC__c objC = New ObjectC__c(Name='VKS__C',ObjectA_Lookup__c =:RecA.id, ObjectB_Lookup__c =:objB.id);

                                inset objC;

                }