+ Start a Discussion
Mohammadasif SiddiquiMohammadasif Siddiqui 

Create a VF page to display child record base on the parent record and Include edit link on each child record.

I have to complete this task, can anyone provide me code

Thanks in advance

Best Answer chosen by Mohammadasif Siddiqui
Mohammadasif SiddiquiMohammadasif Siddiqui
<apex:page controller="Task2Apex">
    <apex:form >
        <apex:pageBlock title="Account Name" >
            <apex:selectList value="{!selectedAccId}" size="1">
                <apex:selectOptions value="{!AccountNames}" />
                <apex:actionSupport event="onchange" action="{!showContacts}" reRender="op" />
         <apex:outputPanel id="op">
            <b><apex:outputText value="Related Contacts" rendered="{!renderPBtable}"/></b>
            <b><apex:outputText value="No Contacts on this Account" rendered="{!noContact}" style="color: red;"/></b>
            <apex:pageblockTable title="Contacts" value="{!conlist}" var="sc" id="relatedContactsBlock" rendered="{!renderPBtable}">
                <apex:column width="100" headerValue="Actions">
                     <apex:outputLink value="/{!sc.id}/e">Edit</apex:outputLink>
                <apex:column value="{!sc.name}"/>
                <apex:column value="{!sc.phone}"/>
public class Task2Apex {

    public Id selectedAccId{get;set;} 

    public List<Contact> conlist {get;set;}   
    public Boolean renderPBtable {get;set;}
    public Boolean noContact {get;set;}

    public List<SelectOption> getAccountNames() {
        List<SelectOption> accOptions= new List<SelectOption>();
        accOptions.add( new SelectOption('','--Select--'));
        for(Account acc : [select Id,name from Account ] ) {
            accOptions.add(new SelectOption(acc.Id,acc.name));
        return accOptions;

    public PageReference showContacts(){
        conlist=[select name,phone from Contact where Accountid=: selectedAccId];
        if(conlist.size() > 0)
            renderPBtable = true; 
            noContact = false;
            renderPBtable = false;
            noContact = true;
        return null;