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
pdvaporpdvapor 

Custom List Controller not Filtering Account ID

I have created a custom object (Product_Sales__c) that is related to Accounts and when I try to create a custom list button on the related list to allow me to edit multiple records associated to an account, it brings back ALL Product Sales records when I am trying to filter by the current Account.  How can I bring the current Account ID into my VFP to filter my list?

 

Class

public class UpdateProductSalesExt{
    public List<Product_Sales__c> sales = new List<Product_Sales__c>([select id from product_sales__c where account__r.id = :ApexPages.currentPage().getParameters().get('id')]);
    public UpdateProductSalesExt(ApexPages.StandardSetController controller) {
        controller.setPageSize(100);
    }
}

 VFP

<apex:page standardController="Product_Sales__c" recordSetVar="sales" tabStyle="Product_Sales__c" extensions="UpdateProductSalesExt">
    <apex:form >
        <apex:pageBlock title="Edit Product Sales" mode="edit">
            <apex:pageMessages />
            <apex:pageBlockButtons location="top">
                <apex:commandButton value="Save" action="{!save}"/>
                <apex:commandButton value="Cancel" action="{!cancel}"/>
            </apex:pageBlockButtons>
            <apex:pageBlockTable value="{!sales}" var="ps">
                <apex:column value="{!ps.Account__c}"/>
                <apex:column value="{!ps.Product__r.Product_Category__c}"/>
                <apex:column value="{!ps.Product__c}"/>
                <apex:column headerValue="Total Wallet">
                    <apex:inputField value="{!ps.Total_Customer_Wallet__c}"/>
                </apex:column>
                <apex:column headerValue="Estimated Percentage of Total Wallet">
                    <apex:inputField value="{!ps.Estimated_Percentage_of_Wallet__c}"/>
                </apex:column>
            </apex:pageBlockTable>      
        </apex:pageBlock>
    </apex:form>
</apex:page>

 

bob_buzzardbob_buzzard

This sounds like you'd be better off using a custom list controller.  There's info and an example in the Visualforce Developer's Guide at:

 

http://www.salesforce.com/us/developer/docs/pages/Content/pages_custom_list_controller.htm

pdvaporpdvapor

Thanks Bob,

However, I now cannot seem to get my Custom List Button to direct it to my VF Page.  In my above example I used it as an extension to the Standard Controller, but now am not able to reference it for the button.  Here's my code.

 

Class

public class updateSalesCon {
  // ApexPages.StandardSetController must be instantiated  
    
  // for standard list controllers  
    
    public ApexPages.StandardSetController setCon {
        get {
            if(setCon == null) {
                setCon = new ApexPages.StandardSetController(Database.getQueryLocator(
                      [select Product_Purchases_from_Sales_Rep__c, Account__c, Estimated_Percentage_of_Wallet__c, Product_Category__c, Total_Customer_Wallet__c 
                       from Product_Sales__c
                       where Account__r.Id = :ApexPages.currentPage().getParameters().get('id')]));
            }
            return setCon;
        }
        set;
    }

    // Initialize setCon and return a list of records  
    
    public List<Product_Sales__c> getProductSales() {
         return (List<Product_Sales__c>) setCon.getRecords();
    }
}

 Page

<apex:page controller="updateSalesCon">
    <apex:pageBlock >
        <apex:pageBlockTable value="{!productsales}" var="ps">
            <apex:column value="{!ps.Account__c}"/>
            <apex:column value="{!ps.Product_Category__c}"/>
        </apex:pageBlockTable>
    </apex:pageBlock>
</apex:page>

 

bob_buzzardbob_buzzard

Ah, okay.  That won't quite fly, as you need the standard controller to be able to use it in that way.

 

However, I'd imagine you can do this in an extension controller and just build your own list of records rather than those exposed through the standard set controller.