+ Start a Discussion
wsuycottwsuycott 

Mass edit all records related to parent record

We have a custom object related to our Opportunity record and would like to use a mass edit of all records related to the parent Opportunity record.  The VF we have now is using the standard controller for the object as follows - however when we attempt to limit the records selected via the id passed in (i.e. https://tapp0.salesforce.com/apex/EditProducts?Opportunity__c=00660000008G7Ts ) the standard controller won't use the reference passed in to only return the records under the opportunity with the above ID - instead it shows the first 20 records of in the Products_and_Services__c object regardless of ID passed. 
 
In testing, instead of the ID of the parent Opportunity I also passed the id of just 1 specific Products_and_Services__c object (i.e. https://tapp0.salesforce.com/apex/EditProducts?id=a0060000009GxfH ) and still get the same reaction so it appears that the controller isn't referencing the id regardless of the base.  What action does the "recordSetVar" invoke and what name is it looking for ( the object API name is Products_and_Services__c, the object plural name is "Products and Services"). This record is in a master-detail relationship with the Opportunity record.
 
<apex:page standardController="Products_and_Services__c"
  recordSetVar="Products_and_Services__c" tabstyle="Opportunity" sidebar="false">
<apex:form >
<apex:pageBlock >
<apex:pageMessages />
<apex:pageBlockButtons >
  <apex:commandButton value="Save" action="{!save}"/>
  <apex:commandButton value="Cancel" action="{!cancel}"/>
</apex:pageBlockButtons>
<apex:pageBlockTable value="{!Products_and_Services__c}" var="prds">
<apex:column headerValue="Prod#"
 value="{!prds.Name}">
</apex:column>
<apex:column headerValue="Product Name"  value="{!prds.Product_Name__c}">
  </apex:column>
    <apex:column headerValue="Proc.Fee">
       <apex:inputField value="{!prds.Processing_Fee__c}"/>
     </apex:column>
     <apex:column headerValue="Mnt.Term(months)">
      <apex:inputField value="{!prds.Processing_Term__c}"/>
     </apex:column>
   </apex:pageBlockTable>
  </apex:pageBlock>
 </apex:form>
</apex:page>
Qingsong LiQingsong Li
you have to use standard controller extensions, please see below examples
Code:
public class extProductsServices{
    private final Products_and_Services__c ProductsServices;
    List<Products_and_Services__c> lstProductsServices;
    Opportunity ProductsServicesNew;
    public extProductsServices(ApexPages.StandardController controller) {
        this.ProductsServices= (Products_and_Services__c)controller.getRecord();
        Id Opps= [Select Opportunity__c FROM Products_and_Services__c 
                    where Id =: ApexPages.currentPage().getParameters().get('id')].Opportunity__c;
        lstProductsServices = (List<Products_and_Services__c>)[Select Id, Processing_Fee__c, 
                                Processing_Term__c, Opportunity__c,Product_Name__c 
                                From Products_and_Services__c
                                where Opportunity__c =: Opps];   
        ProductsServicesNew = [Select Id, Name From Opportunity Where Id =: Opps];
    }
    public List<Products_and_Services__c> getlstProductsServices(){
        return lstProductsServices;
    }
    public Opportunity getProductsServicesNew(){
        return ProductsServicesNew;
    }
    
    public PageReference save() {
            update lstProductsServices;
            return (new ApexPages.StandardController(ProductsServicesNew)).view();
    }         
}

 and then change your page from: 
Code:
<apexage standardController="Products_and_Services__c"
  recordSetVar="Products_and_Services__c" tabstyle="Opportunity" sidebar="false">
<apex:form >
<apexageBlock >
<apexageMessages />
<apexageBlockButtons >
  <apex:commandButton value="Save" action="{!save}"/>
  <apex:commandButton value="Cancel" action="{!cancel}"/>
</apexageBlockButtons>
<apexageBlockTable value="{!Products_and_Services__c}" var="prds">
<apex:column headerValue="Prod#"
 value="{!prds.Name}">
</apex:column>
<apex:column headerValue="Product Name"  value="{!prds.Product_Name__c}">
  </apex:column>
    <apex:column headerValue="Proc.Fee">
       <apex:inputField value="{!prds.Processing_Fee__c}"/>
     </apex:column>
     <apex:column headerValue="Mnt.Term(months)">
      <apex:inputField value="{!prds.Processing_Term__c}"/>
     </apex:column>
   </apexageBlockTable>
  </apexageBlock>
 </apex:form>
</apexage>
to
Code:
<apexage standardController="Products_and_Services__c" extensions="extProductsServices"  
  recordSetVar="Products_and_Services__c" tabstyle="Opportunity" sidebar="false">
<apex:form >
<apexageBlock >
<apexageMessages />
<apexageBlockButtons >
  <apex:commandButton value="Save" action="{!save}"/>
  <apex:commandButton value="Cancel" action="{!cancel}"/>
</apexageBlockButtons>
<apexageBlockTable value="{!lstProductsServices}" var="prds">
<apex:column headerValue="Prod#"
 value="{!prds.Name}">
</apex:column>
<apex:column headerValue="Product Name"  value="{!prds.Product_Name__c}">
  </apex:column>
    <apex:column headerValue="Proc.Fee">
       <apex:inputField value="{!prds.Processing_Fee__c}"/>
     </apex:column>
     <apex:column headerValue="Mnt.Term(months)">
      <apex:inputField value="{!prds.Processing_Term__c}"/>
     </apex:column>
   </apexageBlockTable>
  </apexageBlock>
 </apex:form>
</apexage>

 
Hope it's helpful.
 
Qingsong
CTU007CTU007

I got the same problem, why it lists only 20 records from the child object? I have 30+ records there.

 

Do I have to use a controller extension? I am not able to write any apex code and unit test code yet.

 

CTU007CTU007

Also, what is the default sorting based on?

 

How do I set sorting on a specific field in the list?

 

 

EnthEnth

Did you ever find out why only the first 20 records are displayed, I have the same issue, and would rather not have to implement my own paging solution to bring records back in batches of 20.

 

I thought I could set the page size in the controller but no joy with this so far. Worth looking at this though: Visualforce Pagination

EnthEnth

Sorted! Thanks to StandardSetController with Database.QueryLocator.

 

I was calling setPageSize in my extension constructor and not after calling Database.QueryLocator. Obvious once you see the answer!