+ Start a Discussion
MktdevMktdev 

Nested Query Update

I am trying to update Parent and child object using Nest Query but child records are not getting saved.

 

Public List<Account> getAccount(){
list<Account> acc = [select Id, Name,Country, (select Id, FirstName,LastName,Email from contact) from account where Id=: a.Id];
return acc;
}

 

<apex:repeat var="a" value="{!Account}">
    <apex:outputText value="{!a.Name}"/>
      <apex:repeat var="c" value="{!a.Contacts}">
        <apex:inputfield value="{!c.FirstName}">
        <apex:inputfield value="{!c.LastName}">
        <apex:inputfield value="{!c.Email}">
      </apex:repeat>
<apex:repeat>

 

Best Answer chosen by Admin (Salesforce Developers) 
SRKSRK
i belive you have to update it like
update acc [0].Contacts;

Or
list<contact> con = new list <contact>();
for(Account TempAcc : acc )
{
con.addall(TempAcc.Contacts);
}
update con;

All Answers

SRKSRK
i belive you have to update it like
update acc [0].Contacts;

Or
list<contact> con = new list <contact>();
for(Account TempAcc : acc )
{
con.addall(TempAcc.Contacts);
}
update con;
This was selected as the best answer
MktdevMktdev

Thanks SRK!

 

Yes, Iater I also figured it out we have to iterate our the subset to update the child records.

 

Still thanks for responding.!