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

Trying to get AccountID from Opportunity VF Page
I am working on a VF page to display Account contacts in the Opportunity. Within my class I have written a SOQL query to pull these contacts, but for some reason I can't reference the Opportunity.AccountID. Within my query I am simply stating:
[select id, AccountID, FirstName, LastName, Phone, Email, Question_Answer__c, Role__c, Secondary_Role__c,Tertiary_Role__c, Create_Profile__c from Contact Where AccountID = :ApexPages.currentPage().getParameters().get('AccountID') ORDER BY LastName];
When I debug, the AccountID is passing as a null value.
Any suggestions on how I can gather the Opportunity AccountID and use it within my select statement?
the safest way is to query the fields you need on the opportunity (field accountId) in the constructor (or via an action method called in VF page as like it is in my example). Then you use that variable (myOpportunity.AccountId) in your query to get the contacts.
.
All Answers
hi,
Is Opportunity the controller of the Visualforce page?
Yes, I am using the Opportunity standard controller.
I would use an extension to the std controller to manage that.
Your page would look like this:
<apex:pageaction="{!refresh}" standardController="Opportunity"extensions="OpportunityExtensionController">
In the that class we would have something like this:
.
.
.
.
public OpportunityExtensionController (ApexPages.StandardController stdController) {
this.stdController = stdController;
String id = stdController.getId();
if(id == null || id == '')
{
ApexPages.addMessage(new ApexPages.Message(ApexPages.Severity.FATAL,ERROR_ID_MISSING));
}
}
public void refresh(){
myOpportunity = [select id, AccountId, name
from Opportunity where id = :this.stdController.getId()];
}
.
.
.
.
I hope it helps
I actually am using an extension within my page. It is below:
The only issue is with the WHERE statement in my select query. The 'AccountID' comes through as a null value...
Hi,
Check wether this work,
public class AccountContacts{
public string aId = ApexPages.CurrentPage().getParameters().get('id');
Public Opportunity oppty {set;get;}
oppty = new Opportunity();
}
public list<Contacts> getCon(){
WHERE AccountID =: aId ORDER BY CreatedDate DESC];
return cons;
}
public void insertCon()
{
Oppty.Email=cons.Email;
insert oppty;
oppty = new Opportunity();
}
}
@taaa, thanks for the input. Unfortunately your controller is just pulling the ID of the standard object. Because the oppty is my standard object, the below will simply just give me the oppty ID:
Any other suggestions? This seems so simple, yet so difficult considering it's a standard field on the opp...
the safest way is to query the fields you need on the opportunity (field accountId) in the constructor (or via an action method called in VF page as like it is in my example). Then you use that variable (myOpportunity.AccountId) in your query to get the contacts.
.
Unfortunately you are right, the only thing I could get working was a query...would rather have not used one, but at least its working!! Thanks for all of the help,