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 

Pageblock Edit Mode does not update subquery fields in My visualforce page

Hi All;


I have Pageblock mode = edit in my VF page

I can only update the values from the parent SOQL query but no values from the subquery although I can display both values.


Below is my code and a screen shot. ( I added the basic lines to explain further)


 <apex:PageBlock mode="edit" id="block">


<apex:datatable value="{!searchResults}"  var="r" columns="10">
<!--   <apex:column headervalue="FirstName" style="width:200px"/> <apex:column headervalue="LastName" style="width:200px" /><apex:column headervalue="Time" style="width:200px"/>-->
   <apex:column >
  <apex:inputField value="{!r.Name}"/>&nbsp;&nbsp;
    <apex:column >
  <apex:inputField value="{!r.First_Name__c}"/>

         <apex:datatable value="{!r.Referral_Appointments__r}" var="a" >
    <apex:column >
           <apex:inputField value="{!a.Partner_Service_Provider__c}"/> <- does not update


My query from the controller:

 public list<new_referral_client__c> searchResults {get; set;}

public list<Referral_Appointment__c> ReferralApp1 {get; set;}



public PageReference search() {
  if (searchText != null && searchtext.length() > 0)
    string selectstatement = 'select id,(select, a.Appointment_date__c,a.timepick__c, a.partner_service_Provider__c,status__c from Referral_Appointments__r a), Name, First_Name__c,Last_Name__c,Cell_Phone__c,Last_4_digits_of_ssn__c,Referral_Type__c from new_referral_client__c ' ;
    string wherestatement = 'where (OwnerId = ' + '\'' +UserInfo.getuserID() + '\')' + ' and Last_Name__c LIKE \'%'+searchText+'%\'   order by Last_Name__c  ';   
    string qry =   selectstatement + wherestatement;  
     searchResults = Database.query(qry);


I can update fields Name, First_Name__c,,Last_Name__c etc....

but not  a.Appointment_date__c,a.timepick__c, a.partner_service_Provider__c,status__c which is my subquery.


This is where the update occurs

public PageReference save() {
   // if (searchResults != null)
    //   {
        update searchResults; <- this updates in edit mode
        update ReferralApp1; <- not sure how to update the subquery values in edit mode Thought it would do it by default.


Thank You for your help.










The update of the searchresults only writes back that object, it doesn't traverse the related object graph.


I would think you should simply be able to write back the related list for this:


update searchResults.Referral_Appointments__r;