+ Start a Discussion

Insert multiple records in related object respective to single id of Another object

Hi All,


I have one special requirment just Suppos I have three objects, Specimen, Tests and  SpecimenTest, now On VF page I am  getting specimen Fields and on the Selection of any other object I am getting mulitple tests means more than 1. No if I click on save than  in SpecimenTest  object Multiple tests which I got should be save with Single specimenID  ( where Specimen and Test object has relation as look up relation in SpecimenTest object ).


So result will be If SpecimenID = 00001 and TestIDs are 00001, 00002, 00003 than in SpecimenTest table records will be like


SpecimenTest  SpecimenID  TestID

00001                  00001              00001

00002                  00001              00002

00003                  00001              00003



Please help Me in this,, Thanks in Advance





Make your query as you are doing, but you'll have to nest (do a join query) to keep everythying organized. (this is the prefered way since it's less complex)




List<Account> accounts = [Select Id, Name,  (Select Id, Name From Opportunities) From Account];



On your visualforce page when you grab your results you can do 2 repeats



<apex:repeat value="{!accounts}" var="a">

     <apex:repeat value="{!a.Opportunities}" var="o">









Keep in mind, this all depends on how you have your structure set up