You need to sign in to do that
Don't have an account?
yamini
How to display the related contacts of account in the same visual force page
Hi,
I want to display the account and related contacts in the same visual force page. Actually i am achieved this like,
i am displayed the account names in first page block and am kept the command link for that account names if we click on that command link that will displayed the contacts related to that particular account in another pageblock. But, Now i want to display the account name first and all related contacts line by line. like that i want to displat the contacts for all accounts. please any one help me how to solve this...
example
Maple Lawn Office III 8161 Maple Lawn Blvd Fulton, MD 20759 Contact: Lydia Chandlee | G & R Management 840 First Street, NE Washington, DC 20002 Phone: 301-807-0271 Fax: 202-898-0053 Email: Contract: No | Inspection Date: 4/6/2010 Inspection Type: Annual 5 Year Test: 2012 Reg/Serial #: HO1863 Service Company: Kone Equipment Type: Passenger Hydraulic Annual Price (per unit): $180 Semi-Annual Prince (per unit): $80 |
Maple Lawn Office III 8161 Maple Lawn Blvd Fulton, MD 20759 Contact: Lydia Chandlee | G & R Management 840 First Street, NE Washington, DC 20002 Phone: 301-807-0271 Fax: 202-898-0053 Email: Contract: Yes | Inspection Date: 4/6/2010 Inspection Type: Annual 5 Year Test: 2012 Reg/Serial #: HO1863 Service Company: Kone Equipment Type: Passenger Hydraulic Annual Price (per unit): $180 Semi-Annual Prince (per unit): $80 |
thanks,
yamini
Hi,
Thanks a lot. Its working
Thanks,
yamini
All Answers
Can you clarify the behaviour you are looking for?
I.e. are you wanting to have a line per contact, with the account information repeated in the first column? In your example, its not clear to me what is an account and what is a contact.
Its highly likely you'll need to use wrapper classes that represent a line in a table.
So if I understand correctly, you want to display the account and all of its contacts on a single line?
In that case you may not need a wrapper class at all. If you pull back the account and its related contacts via a single SOQL call, you'll have the object graph in a usable format, and should be able to do something like the following:
Hi,
i got this error
System.SObjectException: SObject row was retrieved via SOQL without querying the requested field: Account.Contacts.
could you please send me the query.
Thanks,
yamini
Hi,
The code which you have sent is working well...But i want to dispaly username at the top of the list...that means i want
output like this....
I wrote a controller like:
usename 1 :xxxxxxxxxx
............................................
Account name:
contact1
contact2.
.
.
..
Account name
Contact1
Contact2
Contact3
.
.
.
.
......................................................
Username2:xxxxxxxxxxxxxxxx
...........................
Account name:
contact1
contact2.
.
.
..
Account name
Contact1
Contact2
Contact3
i want out put like this i mean first list has to show the accounts and contacts which were created bu first user..and secod list has to show to account and contact details which were created by secod user....
Please help me out..
Thanks & Regards
RAju.B
You'll need a wrapper class for this - a class which combines a user and all their accounts.
Something like the following should do it:
and you can use this in the page like so:
Hi,
Thanks for the code, its workring..But in the place of user name , it displaying user id.....
i mean it displaying 00590000000dvS6AAI...but i want the user name of that id...
Please help me....
Thanks & Regards
Raju.b
Try pulling back the name of the owner, e.g.
and then add UserName to the wrapper class etc.
Hi,
The code which you have sent is working. Thanx a lot. But the in the place of username it diplays the user id.
I tried with the createdby.name in query and am taken username in the wrapper class but it gives error like
System.StringException: Invalid id: Boggarapu Nagalakshmi
Class.accountcontact1.: line 11, column 35 External entry point
I used code like:
<apex:page controller="accountcontact1">
<table>
<apex:repeat value="{!accounts}" var="accWrap">
<tr> <td>
<apex:outputText value="User ID : {!accWrap.username}"/>
</td></tr>
<apex:repeat value="{!accWrap.accounts}" var="acc">
<tr><td>
<apex:outputText value="Account : {!acc.Name}"/>
</td></tr>
<apex:repeat value="{!acc.contacts}" var="cont">
<tr><td>
<apex:outputText value="Contact : {!cont.Name}"/>
</td></tr>
</apex:repeat>
<tr><td><hr/></td></tr>
</apex:repeat>
</apex:repeat>
</table>
</apex:page>
plese help me how to solve these.
Thanks,
Yamini
Hi yamini,
Try like these. i think u got the solution
visual force page:
<apex:page controller="accountcontact1" renderAs="pdf">
<table>
<apex:repeat value="{!accounts}" var="accWrap">
<!-- <tr> <td>
<apex:outputText value="User ID : {!accWrap.userid}"/>
</td></tr>-->
<tr> <td>
<apex:outputText value="User name: {!accWrap.username}"/>
</td></tr>
<apex:repeat value="{!accWrap.accounts}" var="acc">
<tr><td>
<apex:outputText value="Account : {!acc.Name}"/>
</td></tr>
<apex:repeat value="{!acc.contacts}" var="cont">
<tr><td>
<apex:outputText value="Contact : {!cont.Name}"/>
</td></tr>
</apex:repeat>
<tr><td><hr/></td></tr>
</apex:repeat>
</apex:repeat>
</table>
</apex:page>
thanks,
lakshmi.
You still have to key the map by id to ensure you correctly set up the accounts by user id. Should be a small change, highlighted below:
Hi,
Thanks a lot. Its working
Thanks,
yamini
Hi,
Can any one tell me How to display the above output in pageblocktable.Means How to display the related contacts of account in the same visual force page pageblocktable.
Regards,
veeru
Hi Veeru,
Try the code which has posted in this post. Its working fine...
Thanks
Hi lakshmi ,
ya i have seen the code exicuted its working fine,but i want the output should be in pageblocktable instead datatable.
Thanks&Regards,
veeru
hi Bob
its working fine k but, i want to display it dynamicallly not on page load i have a button show contacts and
i need to display contacts in PB table whnever i click a button .
can u suggest haw could i do dis.
Thanks in Advance
Has anyone done this using pageblock sections?
Please help.
Hi Bob,
How to write test class for wrapper class in this scenario?
Thanks,
Shiva
<apex:repeat value="{!accs}" var="acc">
<tr>
<td><apex:outputText value="{!acc.Name}"/></td>
<apex:repeat value="{!acc.Contacts}" var="cont">
<td><apex:outputText value="{!cont.Name}"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>
from this code i am getting all contact of a account ,but i want only one contact (with out any class)
My Req. is little bit diffrent as compare with it.I am displaying an account hierarchy on a visualforce page.now with every acconts it must show its related records.like :
Hiearchy->
Acc1->Con1,con2
Acc2->Con1,Con2
Acc3->Con1,Con2
Is this possible?If yes then how?
can anyone help me??
you can try below code
<apex:repeat value="{!act}" var="a">
<apex:outputText value="Account: {!a.name }, "/>
<apex:repeat value="{!a.contacts}" var="cont">
<apex:outputText value="Contact: {!cont.name} "/>
</apex:repeat>
<br/>
<br/>
</apex:repeat>
In the first page, input some characters and click search button to show the search results in the below table. Besides, clicking those item links will lead to the second page to edit.
Visualforce Page:
Controller: Hope it helps!
Can any one help me How to display the below output in pageblocktable.How to display the user opportunities and lead in visual force page pageblocktable
Owner Total Leads Total Opps. Conv Rate Max Created Date (Opp) Total Val (Opp)
John
Smith 20 5 25.00% 12/15/2014 $20,000.00
mike
jones 10 1 10.00% 12/12/2014 $3,000.00
------------------------------------------------------------------------------------------------------------------------------------------
Requirements
Column Requirement
------------ ----------------------
Owner Name of the user
Total Leads Total Leads of owner by created date (Date filter applies to created date)
Total Opps. Total Opportunities of owner by closed date where stage = Closed Won
(Date filter applies to closed date)
Conversion Rate Total Opps./ Total Leads in Percentage format
Max. Created Date (Opp.) Created Date of the most recent Opportunity
Total Value Total Values of the Opportunities
http://salesforcecodes.com/display-related-contacts-when-we-click-on-account-record-using-lightning-component/
hai can you help me the same Requirement
Hi Umesh Rathi
Can we do that as a pageblock table because I want to show account and contact just like
Account contact
1 1
2 2
3 3
just like that I want to show
Please try this:
Hope this helps!
Thanks,
Umesh Rathi
Can any one help me How to display the below output in LWC.How to display the user opportunities and lead in LWC
Owner Total Leads Total Opps. Conv Rate Max Created Date (Opp) Total Val (Opp)
John
Smith 20 5 25.00% 12/15/2014 $20,000.00
mike
jones 10 1 10.00% 12/12/2014 $3,000.00
------------------------------------------------------------------------------------------------------------------------------------------
Requirements
Column Requirement
------------ ----------------------
Owner Name of the user
Total Leads Total Leads of owner by created date (Date filter applies to created date)
Total Opps. Total Opportunities of owner by closed date where stage = Closed Won
(Date filter applies to closed date)
Conversion Rate Total Opps./ Total Leads in Percentage format
Max. Created Date (Opp.) Created Date of the most recent Opportunity
Total Value Total Values of the Opportunities
hey can you help me the same Requirement