You need to sign in to do that
Don't have an account?
JAW99
Filtering a display of related objects in a VF page
Have the sample code, but I am having issues in modifying it in 2 ways -
- I want to display a custom object, but am having trouble replacing the contacts
- I want to only display records with a certain field value (Product = United)
any help with ficing the output and filtering based on field value much appreciated
<apex:page standardController="Account" > <apex:pageBlock > <apex:form > <apex:pageBlockTable value="{!account.Contracts}" var="Contract"> <apex:column headervalue="Contract Number"> <apex:outputLink value="https://na2.salesforce.com/{!Contract.id}" target="_top" id="theLink">{!Contract.contractNumber}</apex:outputLink> </apex:column> <apex:column value="{!Contract.Contract_Type__c}"/> <apex:column value="{!Contract.status}"/> <apex:column value="{!Contract.ownerid}"/> <apex:column value="{!Contract.ActivatedDate}"/> </apex:pageBlockTable> </apex:form> </apex:pageBlock> </apex:page>
Presumably the custom object is a related list on the account object? That being the case you should be able to use the __r notation. If your custom object has an API of My_Custom__c, then the related list default name will be My_Customs__r.
You should then be able to apply the filter to the rendered attribute of the apex:column.
So something like the following should do the trick:
If the product__c field is a picklist, you'll need to use the TEXT function to be able to compare it to a literal value.
I am getting an error
of
Error: Invalid field Custom_ObjectName__r for SObject Account
You have to replace that with the relationship api name for your object model.
Yes of course, I had the real object name in my code, just redacted it for the forum.
That means that you haven't used the correct name - does that relationship exist?
Yes, whoops, error in the plural nature of the related objects.
Can you assist with filtering so it returns objects of only type based on a field value?
Whoops just missed the filtering via render in the code above.
got it to save but it's not filtering
here
still renders info where the department equals things other than the example.
Hmmm...
You'd need to have the rendered condition on each of the columns. However, if the first element in the list doesn't match the filter condition, you won't get any headings either I've just found out.
I'm sure I've got something like this working before, but I think I may have been using vanilla HTML tables and this had far more control over the layout.
Thanks for you help so far. The filtering of the list is key to the whole point of the VF page.
If anyone else has some ideas or can point me to instances it would be much appreciated.