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
giorgio70giorgio70 

Mass edit and save of Related List records in a Visualforce custom page

Hello

 

I have two custom objects with a one to many relationship: Programs can receive multiple Reviews. 

 

I have developed a simple page that allows me to edit and save several review records at the same time, using standard list controller. See the code below. This will list ALL the reviews in my organization, allow me to make changes and save all the review records I modify

 

Now I would like to use the same functionality to be able to edit all the reviews that are related to a particular program. From within the Program record related list, I created a button that executes this Visualforce page, but this brings up ALL the reviews records, and not only those in the related list. How can I tell my Visualforce page to only display the records in the related list?

 

Thanks in advance for your help

Giorgio

 

 

 

<apex:page standardController="Review__c" recordSetVar="review__c">
<apex:form >

  <apex:pageBlock >
  <apex:pageBlockButtons >
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlockButtons>
    <apex:pageBlockTable value="{!Review__c}" var="a">
      <apex:column value="{!a.name}"/>
      <apex:column headerValue="Review Approved?">
         <apex:inputField value="{!a.Review_Approved__c}"/>
      </apex:column>

    </apex:pageBlockTable>
  </apex:pageBlock>

</apex:form>
</apex:page> 

 

bob_buzzardbob_buzzard

You are seeing all review records because of the type of controller you are using on the page:

 

<apexage standardController="Review__c" recordSetVar="review__c">

 

 

 

is a standard set controller for the Review__c custom object.  This controller doesn't know about Programs.

 

You could put the form into a component and pass the reviews to be maintained into it as an attribute.  That way you could use it for all reviews or for a subset that you had extracted.

giorgio70giorgio70

Thanks Bob,

 

I hope I am getting closer. I have created a component as you suggested, see below. The component has an attribute to receive the list of Reviews that need to be edited.

 

Now my problem is to "call" this component from a Program record, upon clicking a custom button "EDIT REVIEWS" on the "Reviews" related list within the Program record.

I need to display the list of reviews, allow editing them and saving all the changes I make.


Do I need a Custom Controller to do this, or what controller should I use (Review__c or Program__c) in my Visualforce page to make sure I display a page with the reviews and be able to edit/save them? 

 

And what would be the sintax to use on the VF page in order to pass my related list records to the component?

 

This is what I have:

 

<c:Edit_List_of_Reviews Reviews="{!Reviews__r}"/>

 

 

Hope you can help

Giorgio 

 

-----------

This is the component, called Edit_List_of_Reviews 

 

 

<apex:component>
<apex:attribute name="Reviews"
                type="Review__c[]"
                description="List of reviews to be edited"
                required="true"/>

<apex:form >

  <apex:pageBlock >
  <apex:pageBlockButtons >
      <apex:commandButton value="Save" action="{!save}"/>
   </apex:pageBlockButtons>
    <apex:pageBlockTable value="{!Reviews}" var="a">
      <apex:column value="{!a.name}"/>
      <apex:column headerValue="Review Approved?">
         <apex:inputField value="{!a.Review_Approved__c}"/>
      </apex:column>

    </apex:pageBlockTable>
  </apex:pageBlock>

</apex:form>
</apex:component>

bob_buzzardbob_buzzard
If it was me, I'd have an extension controller for the Program standard controller.

 

Your custom button would direct to the "EditReviews" page, with the id of the Program as a parameter.

 

 

Within the page you would call the component:

 

<c:Edit_List_of_Reviews Reviews="{!programReviews}"/>

 

and you would have a method in your extension controller called "getProgramReviews" that built the list of Reviews associated with the program that is available from the standard controller.