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

how to get the account id of contact
here is my code (i just dont want to give hard code id ) . plz guide me
----------------------------------------
<apex:page standardController="contact" extensions="pg">
<apex:form >
<apex:inputField value="{!contact.accountid}"/>
</apex:form>
<apex:form >
<apex:pageBlock title="contact details">
<apex:pageBlockSection columns="2">
<apex:pageBlockTable value="{!cont}" var="co">
<apex:column value="{!co.lastname}"/>
<apex:column value="{!co.phone}"/>
<apex:column value="{!co.email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="oppty details">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!oppty}" var="op">
<apex:column value="{!op.name}"/>
<apex:column value="{!op.Amount}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
--------------------
public class pg {
public pg(ApexPages.StandardController controller) {
cont=[select id, firstname, lastname , email,phone from contact where accountid =:'cont.accountid'];
oppty=[select name, amount from opportunity where accountid='0019000001CuKu3'];
}
public list<contact> cont { get; set; }
public list<opportunity> oppty{ get; set; }
public pg()
{
}
}
----------------------------------------
<apex:page standardController="contact" extensions="pg">
<apex:form >
<apex:inputField value="{!contact.accountid}"/>
</apex:form>
<apex:form >
<apex:pageBlock title="contact details">
<apex:pageBlockSection columns="2">
<apex:pageBlockTable value="{!cont}" var="co">
<apex:column value="{!co.lastname}"/>
<apex:column value="{!co.phone}"/>
<apex:column value="{!co.email}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
<apex:pageBlock title="oppty details">
<apex:pageBlockSection >
<apex:pageBlockTable value="{!oppty}" var="op">
<apex:column value="{!op.name}"/>
<apex:column value="{!op.Amount}"/>
</apex:pageBlockTable>
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
--------------------
public class pg {
public pg(ApexPages.StandardController controller) {
cont=[select id, firstname, lastname , email,phone from contact where accountid =:'cont.accountid'];
oppty=[select name, amount from opportunity where accountid='0019000001CuKu3'];
}
public list<contact> cont { get; set; }
public list<opportunity> oppty{ get; set; }
public pg()
{
}
}
cont=[select id, firstname, lastname , email,phone from contact];
oppty=[select name, amount from opportunity where accountid=:cont.AccountId];
is the somthing like this?
public pg(ApexPages.StandardController controller)
{
cont=[select id, firstname, lastname , email,phone from contact where accountid ='0019000001CuKu3'];
oppty=[select name, amount from opportunity where accountid='0019000001CuKu3'];
}
Hi Dany,
If I have understood it properly, you have created a lookup field which on selecting the account it should display the contacts and opportunity.
In that case I have changed it a little in the code. Check if it helps
Regards,
Manjunath
thnx for your response . can we do the same using standard controller . if yes ? plz guide me
Is there a specific reason that you want to go with the standard controller?
Check if this helps!!
Regards,
Manjunath
By the way, as a best practice we shoud not be quering in getter/setter (Gave you as an example.) . Change accrodingly.
Regards,
Manjunath