You need to sign in to do that
Don't have an account?
Limiting results of PageBlockTable to records related to a parent object (Visualforce)
I am very new to Visualforce (last job had its own VF programmer, now I'm having to pick it up), and created a page that creates a list of items, and a button to access the page from the parent, in this case, contracts. The related list is Contract Items (contract_item__c) and I would like to limit the contract items to only the ones related to the specific contract I launch the page from. I'm sure this is answered somewhere, but I apparently do not know what I am looking for, as 2 days of searching has brought me close but not quite there.
<apex:page standardController="Contract_Item__c" recordSetVar="CI" tabStyle="Contract_Item__c" 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="{!CI}" var="c"> <apex:column value="{!c.name}"/> <apex:column headerValue="Item"> <apex:outputField value="{!c.Item__c}"/> </apex:column> <apex:column headerValue="Price"> <apex:inputField value="{!c.FS_Price__c}"/> </apex:column> <apex:column headerValue="Rebate"> <apex:inputField value="{!c.Rebate__c}"/> </apex:column> <apex:column headerValue="Volume"> <apex:inputField value="{!c.FS_Volume__c}"/> </apex:column> </apex:pageBlockTable> </apex:pageBlock> </apex:form> </apex:page>
You can create a VF page based on contracts and show only related list pertaining to Contract Item.In list attribute you have to pass relationship name.
<apex:page standardController="Contract">
<apex:relatedList list="Contract_Items__r" />
</apex:page>
If you don't want this way, you need to create an extension class to your existing VF page and get the required collection like below and expose them in a VF page
public class ContractItemExtension{
List<Contract_Item__c> l{get;set;}
public ContractItemExtension(ApexPages.StandardController c){
l=[select id,name from Contract_Item__c where contract__c=:ApexPages.CurrentPage.getParameters().get('id')];
}
}