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
Sunil Kandel 10Sunil Kandel 10 

Visualforce to show more than 10 columns in related List

Hi all,

I have two objects in Master Detail relationship.
Ticket__c  is a Master and Ticket_item__c is Child.
I have related list of Ticket_item__c in Ticket__c but it is standard page and it will show only 10 columns.
I want to display the Ticket_item_c list in Ticket Page Layout with 12 columns. 
Can you please point any sample visualfore page on how to write this.  

Thank you
Best Answer chosen by Sunil Kandel 10
Ayush TripathiAyush Tripathi
Hi Sunil

When you perform a child to parent query you have to use Child Relationship Name for child object followed by __r. By default it will be your plural name. You can find this on your child object on field(Master-Detail)..How to perform soql query refer this link https://developer.salesforce.com/forums/?id=9060G000000XbH5QAK

However Make the code changes 
 
<apex:page standardcontroller="Ticket__c" extensions = "sample1">
    <apex:pageBlock>

    <apex:repeat value="{!tc}" var="a">


        <apex:pageBlockTable value="{!a.Ticket_Items__r}" var="c">
            <apex:column value="{!c.Name}"/>
            //Here you can write your rese 11 columns
        </apex:pageBlockTable>

    </apex:repeat>

    </apex:pageBlock>
</apex:page>
 
public class sample1
{    
    public List<Ticket__c> tc {get;set;}
    public sample1(ApexPages.StandardController controller)
    {
         Id id =   ApexPages.currentPage().getParameters().get('Id');
        tc = [SELECT Name, (SELECT Name FROM Ticket_Items__r ) FROM Ticket__c  where ID =: id];
//Please see your child relationship name once in my case it isTicket_Items
    }    
}

 

All Answers

Ayush TripathiAyush Tripathi
Hi You can do it by using visualforce 

VisualForce Page
 
<apex:page standardcontroller="Ticket__c" extensions = "sample1">
    <apex:pageBlock>

    <apex:repeat value="{!acct}" var="a">


        <apex:pageBlockTable value="{!a.Contacts}" var="c">
            <apex:column value="{!c.Name}"/>
            //Here you can write your rese 11 columns
        </apex:pageBlockTable>

    </apex:repeat>

    </apex:pageBlock>
</apex:page>

Apex Code
 
public class sample1
{    
    public List<Account> acct {get;set;}
    public sample1(ApexPages.StandardController controller)
    {
         Id id =   ApexPages.currentPage().getParameters().get('Id');
        acct = [SELECT Name, (SELECT Name, Email FROM Ticket_item__c ) FROM Ticket__c  where ID =: id];
    }    
}
After making the page add it into the detail page of Ticket__c  using PageLayout
 
Sunil Kandel 10Sunil Kandel 10

Hi Ayush,

Thank you for your detailed code. Appreciated. I will try at my end and let you know if any errors. I will not forget to come back to mark your anser the best anwer. 

Appreciated.

Sunil Kandel 10Sunil Kandel 10
HI Ayush,

Getting these error while creating a class. I even tried using FX5__Ticket_item__r, but still the same error
Error: Compile Error:
FROM FX5__Ticket_Item__c ) from FX5__Ticket__c
^
ERROR at Row:3:Column:15
Didn't understand relationship 'FX5__Ticket_Item__c' in FROM part of query call. If you are attempting to use a custom relationship, be sure to append the '__r' after the custom relationship name. Please reference your WSDL or the describe call for the appropriate names. at line 8 column 16

Thank you
Ayush TripathiAyush Tripathi
Hi Sunil

When you perform a child to parent query you have to use Child Relationship Name for child object followed by __r. By default it will be your plural name. You can find this on your child object on field(Master-Detail)..How to perform soql query refer this link https://developer.salesforce.com/forums/?id=9060G000000XbH5QAK

However Make the code changes 
 
<apex:page standardcontroller="Ticket__c" extensions = "sample1">
    <apex:pageBlock>

    <apex:repeat value="{!tc}" var="a">


        <apex:pageBlockTable value="{!a.Ticket_Items__r}" var="c">
            <apex:column value="{!c.Name}"/>
            //Here you can write your rese 11 columns
        </apex:pageBlockTable>

    </apex:repeat>

    </apex:pageBlock>
</apex:page>
 
public class sample1
{    
    public List<Ticket__c> tc {get;set;}
    public sample1(ApexPages.StandardController controller)
    {
         Id id =   ApexPages.currentPage().getParameters().get('Id');
        tc = [SELECT Name, (SELECT Name FROM Ticket_Items__r ) FROM Ticket__c  where ID =: id];
//Please see your child relationship name once in my case it isTicket_Items
    }    
}

 
This was selected as the best answer
Sunil Kandel 10Sunil Kandel 10

 

Thank you Ayush, It worked.
Thank you