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
vijendahr kvijendahr k 

need to insert child records inside for loop based on query string split

Hello all, 

 i have scenario, where i need to insert data from obe object ot another object check snippt below
 
   for( account a: acclist)
list<contact> conlist= new list<contact>();
a.f1= aa.f1;
a.f2= aa.f2;0
string[] childemail=aa.childemail__c.split('''); // line 1: childemail__c field contains list of email address, based on email address i have to query                                                                                 contact object and insert, childemail__c contains email1, email2, email 3 data;
    for( contact con: select id, name, email from contact where in:childemail)  // line 2: i am uisng for loop inside for loop to add query records. hoe can i control both scenaios ;
   {  
           contact c= new contact();
          c.email= con.email;
           conlist.add(c);
      
   }
}

Can any one hlep me to remove Soql statement inside for loop and remove anoter for loop inside for loop, your help is very much needed to me to fix this issue. thanks advance. its very urgent to me.