0

I need to be able to query the Contact's Parent Account and show it in apex page but I get an error for this. How do does it know that the person logged in parents to show . So right now in Partner Community there is a field called Parent ID which a user which is the contact has to click on it and then select its parent while making an account. I want to automatically assigned that to the user

public class newOpportunityController {

  public List<Account> parentAccount { get; private set; }
    public List<Account> parentAccount { get; private set; }
    parentAccount = [SELECT Account.Name, (SELECT Contact.LastName FROM Account.Contacts)
                           FROM Account ];

}

1 Answer 1

0

Your question is a bit vague but:

If you are using a standard controller for Contact and your VF page, your class could look like:

public class myTestController{

    public Account parentAccount{get;set;}

    public mytEstController(Apexpages.standardController con){
       //Ensure the AccountID field is pulled into the controller
       con.addFields(New String[]{'AccountID'});
       //Get the Contact record 
       Contact c = (Contact)con.getRecord();
       //Query for the account based on the contact
       parentAccount = [Select ID From Account where ID = c.AccountID];
    }



}

The above is only a start and does not account for the fact that the AccountID field may be on the page. You will need to add appropriate error handling as well

2
  • Thank you for respond , I am using my own controller does that make difference . public class newOpportunityController {
    – Metawaa
    Commented Oct 7, 2015 at 18:32
  • @bez - Yes, there are a lot of thing to take into account. You can start from what I gave you or adapt what you have to using the info learned from this answer
    – Eric
    Commented Oct 7, 2015 at 21:07

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .