You need to sign in to do that
Don't have an account?
bela
please help its urgent,I am trying to display the fields of account and its contacts of oportunity on the pdf page
please help its urgent,on click of generatePDF button on opportunity ,I am trying to display the fields of account and its contacts(not opportunities of only contact) of that oportunity on the pdf page,I am able to display record of account related to opportunity,but i am not able to get and display that accounts related contacts.Please help me in this scenario.below is code.
Unable to query the contacts of account of the opportunity(please help)
Controller:
--------------
public with sharing class diplayacccontofopp {
public list<opportunity> opp{set;get;}
public list<contact> oppcon{set;get;}
public list<contact> con{set;get;}
public list<account> acc{set;get;}
public diplayacccontofopp(ApexPages.StandardController controller) {
Id OppotunityIDs = ApexPages.currentPage().getParameters().get('Id');
map<id,account> mo=new map<id,account>([select id,name From account]);
// opp=[select id, name,account.id,account.name from opportunity where id =:OppotunityIDs ];
//acc= [select id,Name,(select id,FirstName,LastName FROM Contacts ) From Account where id =:opp[0].id];
opp = [select id,AccountId,account.id,account.name From Opportunity WHERE Id=:OppotunityIDs ];
acc=[select id, Name,(Select name,id From Opportunities where id=:OppotunityIDs) from Account ];
oppcon=[SELECT Id, Name,firstname FROM contact where accountId=:acc[0].id];
}
}
VF page:
---------------
<apex:page standardController="opportunity" extensions="diplayacccontofopp" renderAs="PDF">
<table width="100%" style="font-family: Arial, Helvetica, sans-serif; border-collapse: collapse;"
cellpadding="5">
<tr>
<td colspan="4" style="font-size: x-large;">
Opportunity Info
</td>
</tr>
<tr>
<td colspan="2" >
{!Opportunity.Name}
</td>
</tr>
<tr>
<td colspan="15">
</td>
</tr>
<tr>
<td colspan="4" style="font-size: x-large;">
ACCOUNT INFO
</td>
</tr>
<apex:repeat value="{!opp}" var="op">
<tr id="{!op.account.Id}">
<td>
{!op.account.name}
</td>
</tr>
</apex:repeat>
</table>
<!--<table>
<apex:repeat value="{!acc}" var="a">
<tr>
<td></td>
<apex:repeat value="{!a.Contacts}" var="cont">
<td><apex:outputText value="{!cont.firstName}"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>-->
<table>
<apex:repeat value="{!oppcon}" var="a">
<tr>
<td></td>
<apex:repeat value="{!a.Id}" var="cont">
<td><apex:outputText value="{!a.firstname}"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>
</apex:page>
Thanks,
B.Mahanandeesh.
Unable to query the contacts of account of the opportunity(please help)
Controller:
--------------
public with sharing class diplayacccontofopp {
public list<opportunity> opp{set;get;}
public list<contact> oppcon{set;get;}
public list<contact> con{set;get;}
public list<account> acc{set;get;}
public diplayacccontofopp(ApexPages.StandardController controller) {
Id OppotunityIDs = ApexPages.currentPage().getParameters().get('Id');
map<id,account> mo=new map<id,account>([select id,name From account]);
// opp=[select id, name,account.id,account.name from opportunity where id =:OppotunityIDs ];
//acc= [select id,Name,(select id,FirstName,LastName FROM Contacts ) From Account where id =:opp[0].id];
opp = [select id,AccountId,account.id,account.name From Opportunity WHERE Id=:OppotunityIDs ];
acc=[select id, Name,(Select name,id From Opportunities where id=:OppotunityIDs) from Account ];
oppcon=[SELECT Id, Name,firstname FROM contact where accountId=:acc[0].id];
}
}
VF page:
---------------
<apex:page standardController="opportunity" extensions="diplayacccontofopp" renderAs="PDF">
<table width="100%" style="font-family: Arial, Helvetica, sans-serif; border-collapse: collapse;"
cellpadding="5">
<tr>
<td colspan="4" style="font-size: x-large;">
Opportunity Info
</td>
</tr>
<tr>
<td colspan="2" >
{!Opportunity.Name}
</td>
</tr>
<tr>
<td colspan="15">
</td>
</tr>
<tr>
<td colspan="4" style="font-size: x-large;">
ACCOUNT INFO
</td>
</tr>
<apex:repeat value="{!opp}" var="op">
<tr id="{!op.account.Id}">
<td>
{!op.account.name}
</td>
</tr>
</apex:repeat>
</table>
<!--<table>
<apex:repeat value="{!acc}" var="a">
<tr>
<td></td>
<apex:repeat value="{!a.Contacts}" var="cont">
<td><apex:outputText value="{!cont.firstName}"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>-->
<table>
<apex:repeat value="{!oppcon}" var="a">
<tr>
<td></td>
<apex:repeat value="{!a.Id}" var="cont">
<td><apex:outputText value="{!a.firstname}"/></td>
</apex:repeat>
</tr>
</apex:repeat>
</table>
</apex:page>
Thanks,
B.Mahanandeesh.
I suppose you have the opportunity id with you. So get the accountId from opportunity -> SELECT AccountId FROM Opportunity WHERE Id=:opportunityId
Now you have the accountId, so you can query whatever information you require from Account object.
Next step is to display contacts which are present under this account -> SELECT Id FROM Contact WHERE AccountId =: AccountId obtained in step2.
Hope this helps. Thanks.