I am having account table with name,email,.. fields. If i click on one account my requirement is to display its contacts in a table format.
My code is:
<apex:page controller="custable" sidebar="false">
<apex:form >
<apex:pageBlock title="AccountTable">
<apex:pageBlockTable value="{!Acclst}" var="A">
<apex:column headerValue="EDIT">
<apex:outputLink value="/{!A.id}/e" id="edit">Edit</apex:outputLink>
</apex:column>
<apex:column headerValue="DELETE">
<apex:commandLink action="{!deleteAccount}" onclick="if(!confirm('Are you sure?')) return false;">Del
<apex:param value="{!A.Id}" name="idToDel" assignTo="{!recid}"/>
</apex:commandLink>
</apex:column>
<apex:column headerValue="NAME OF THE ACCOUNT" >
<apex:commandLink value="{!A.Name}" action="/{!A.id}"/>
</apex:column>
<apex:column value="{!A.Id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
</apex:page>
controller is:
public with sharing class custable {
public string recid{get;set;}
public string row{ get; set;}
public list<Account> Acclst{get;set;}
Public Account A;
public custable(){
Acclst = [select Id,Name from Account ];
}
public pagereference deleteAccount()
{
account ac=[select id,name from account where id=:recid];
delete ac;
pagereference ref =new pagereference('/apex/custable');
ref.setredirect(true);
return ref;
}
}
previously i redirected to record detail page. But now requirement is to display contacts table when i click on a account record.
Attribution to: PavanFoxPro
Possible Suggestion/Solution #1
You'll need the following for this:
- A list of contacts property in the controller
- A table that iterates a list of contacts from the controller
- An action method that retrieves the list of contacts for the specified account
- A commandlink that executes the action method, passing the account id into the controller, and then rerenders the table of contacts
Something like the following:
Controller:
public with sharing class custable {
public string recid{get;set;}
public string row{ get; set;}
public list<Account> Acclst{get;set;}
Public Account A;
public List<Contact> contacts {get; set;}
public custable(){
Acclst = [select Id,Name from Account ];
contacts=null;
}
public pagereference deleteAccount()
{
account ac=[select id,name from account where id=:recid];
delete ac;
pagereference ref =new pagereference('/apex/custable');
ref.setredirect(true);
return ref;
}
public void setupContacts()
{
contacts=[select id, FirstName, LastName from Contact where AccountId=:recId];
}
}
Page:
<apex:page controller="custable" sidebar="false">
<apex:form >
<apex:pageBlock title="AccountTable">
<apex:pageBlockTable value="{!Acclst}" var="A">
<apex:column headerValue="EDIT">
<apex:outputLink value="/{!A.id}/e" id="edit">Edit</apex:outputLink>
</apex:column>
<apex:column headerValue="DELETE">
<apex:commandLink action="{!deleteAccount}" onclick="if(!confirm('Are you sure?')) return false;">Del
<apex:param value="{!A.Id}" name="idToDel" assignTo="{!recid}"/>
</apex:commandLink>
</apex:column>
<apex:column headerValue="NAME OF THE ACCOUNT" >
<apex:commandLink value="{!A.Name}" action="{!setupContacts}" rerender="conttable">
<apex:param value="{!A.Id}" name="idForConts" assignTo="{!recid}"/>
</apex:commandLink>
</apex:column>
<apex:column value="{!A.Id}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:form>
<apex:pageBlock title="Contacts">
<apex:pageBlockTable value="{!contacts}" var="contact" id="conttable">
<apex:column value="{!contact.id}"/>
<apex:column value="{!contact.FirstName}"/>
<apex:column value="{!contact.LastName}"/>
</apex:pageBlockTable>
</apex:pageBlock>
</apex:page>
Attribution to: Bob Buzzard
Possible Suggestion/Solution #2
@Bob,I'm trying to display contacts under the same account(on click of + symbol for expand) in the form of table not at the bottom of the account table.But particular account columns also coming side by side of contact table.
Attribution to: Bujji
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/33930