You need to sign in to do that
Don't have an account?

Contact list on Case
I would like a VF page block in the Case page. It will have a list of Contacts related to the Account that has been selected on the Case. Can this be done with a standard contoller or do i need a custom controller. Can anyone assist with a sample code or point me to a resource. Thanks.
Hi Here is your solution. you can then embed this vf page in the case layout
public class ContactsForCase {
public case theCase;
public Account acc{get; set;}
public ContactsForCase (apexpages.standardcontroller controller){
theCase = [select id, accountid from case where id =:apexpages.currentpage().getparameters().get('id')];
acc = [select id, name from account where id =:theCase.accountid];
}
public list<contact> getContacts(){
list<contact> myContact = [select id, accountid, name, phone, email from contact where accountid = :acc.id];
return myContact;
}
}
<apex:page standardController="case" extensions="ContactsForCase">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!contacts}" var="c">
<apex:column headerValue="Name">{!c.name}
</apex:column>
<apex:column headerValue="Email">{!c.email}
</apex:column>
<apex:column headerValue="Phone">{!c.phone}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
All Answers
Hello,
apex:relatedList seems to be the simplest way. Use the standardController for Account and pass the AccountId as a parameter in the URL.
Link: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_relatedList.htm
Thanks,
Adrian
This is not quite what I was looking for. I need the VF page on the Case page. I can't use Account as the standard controller.
Sorry, I was thinking that you can somehow fool the layout editor into taking a vf page with a custom link... where you could of added the related Account's Id. You're right it is not possible.
So the other solution is to use the standard controller of the case - > this ensures that the page can be added to the layout. See here: http://blogs.developerforce.com/systems-integrator/2008/11/adding-a-visualforce-page-to-a-page-layout.html
You'll need an extension. Link : http://www.salesforce.com/us/developer/docs/pages/Content/pages_controller_extension.htm
In the constructor of the extension you'll need to retrieve via a soql the Contacts:
In your page you'll need to show the list either using apex:repeat or apex:dataTable. Link: http://www.salesforce.com/us/developer/docs/pages/Content/pages_compref_dataTable.htm
Hope this helps,
Adrian
Hi Here is your solution. you can then embed this vf page in the case layout
public class ContactsForCase {
public case theCase;
public Account acc{get; set;}
public ContactsForCase (apexpages.standardcontroller controller){
theCase = [select id, accountid from case where id =:apexpages.currentpage().getparameters().get('id')];
acc = [select id, name from account where id =:theCase.accountid];
}
public list<contact> getContacts(){
list<contact> myContact = [select id, accountid, name, phone, email from contact where accountid = :acc.id];
return myContact;
}
}
<apex:page standardController="case" extensions="ContactsForCase">
<apex:pageBlock >
<apex:pageBlockSection >
<apex:pageBlockTable value="{!contacts}" var="c">
<apex:column headerValue="Name">{!c.name}
</apex:column>
<apex:column headerValue="Email">{!c.email}
</apex:column>
<apex:column headerValue="Phone">{!c.phone}
</apex:column>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:page>
Thanks wajida. This is exactly what I was looking for. I had a similar use case and I just remembered the solution you gave. I appreciate it. This works perfect.