2

I have a VF page where its nested tables with data and input fields - I wanted to save the values when user enters and clicks the save button, but I want only a single button to save all values to the respected child records.

I have defined a save method, but not getting an idea how to get all in to one map from nesting.

Please throw some light to get me out of here.

My Controller """""""""""""""""""""""""""""""""""""" My Controller methods for getting the records and displaying and save method which i am not able to proceed further :

    public list<Faculty__c> getfaculties2(){  
     faculties = new list<Faculty__c>();        
     faculties = [select Id,Name,Account__r.name,Account__r.id,(select id,name,state__c, from Bookings__r where (state__c IN('Confirmed','Pending') AND CALENDAR_YEAR(move_in_date__c)IN(2015) )ORDER BY state__c ) From Faculty__c where Account__c = :accid limit 100];

     return faculties;
  }
  public pageReference getfaculties(){
  try{
  getfaculties2();
  }catch(exception e){
  my error message here
  }
  return null;} 

  public pagereference save(){       

    //Bookid  = [SELECT id,Name,buy_out__c FROM Booking__c WHERE id=:editid];
   try{

   update faculities;
   }catch(exception e){}  
  return apexpages.currentpage();      
}   

My page looks like attached

and My page is having input field type to enter values by user

so i wanted to have a single button called save all and get save them in bookings object

1
  • Can you explain what you mean by "how to get all in to one map from nesting" a bit more and add some of your code? Saving multiple objects and types of objects is usually just one or more update calls in the controller save method.
    – Keith C
    Commented Jul 3, 2015 at 10:59

1 Answer 1

1

It sounds like as well as updating the Faculty__c objects you want to update the child Booking__c objects. You can do that by combining all the Booking__c object child lists into one list and updating that list:

public pagereference save(){

    update faculities;

    List<Booking__c> bookings = new List<Booking__c>();
    for (Faculty__c f : faculities) {
        bookings.addAll(f.Bookings__r);
    }
    update bookings;

    return apexpages.currentpage();
}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .