Search code examples
salesforceapex-codevisualforceapex

Not able to show related records


I have two custom objects, X and Y.

The object Y is related to X by lookup YretatedX__c.

I am trying to show all Y related to X y standart page of X whith a visualforce.

Visualforce:

<apex:page standardController="X__c" extensions="related_list">
    <apex:detail relatedList="true">
        <apex:relatedList list="Y__c" subject="{!AllRelated}"/> 
    </apex:detail>
</apex:page>

Apex Class:

public class related_list {
    private X__c x;
    private Id idX;
    public List<Y__c> AllRelated = new Y__c[]{};
    public related_list(ApexPages.StandardController controller) {
        this.x=(X__c)controller.getRecord();
        idX = this.x.Id;
    }
    public List<Y__c> getAllRelated() {
        AllRelated = [SELECT id FROM Y__c WHERE YretatedX__c =: this.idX];
        return AllRelated;
    }
} 

In X page, the visualforce only shows:

Invalid parameter value "[a120E0000001234567, a120E0000007654321]" for parameter "id"

This Ids are valid for Y objects retated to this X object

I tried a lot, but I can find a solution.


Solution

  • I found a solution using <apex:pageBlockTable instead of <apex:relatedList

    <apex:page standardController="X__c" extensions="related_list">
        <apex:pageblock id="CustomList" title="Y"  >
            <apex:pageBlockTable value="{!AllRelated}" var="y" rendered="true">
                    <apex:column value="{!y.id}"/>
            </apex:pageBlockTable>
        </apex:pageblock>
    </apex:page>