[SalesForce] Query between Opportunity and Account

I'm a new in this salesforce world.

I have to show Owner | Account Name | Opportunity Name | Last Meeting Date | Amount

I created an Apex Class and VisualForce Page. This is my query

public List<Opportunity> getOpportunity() {
    List<Opportunity> opp = [SELECT o.id, o.ownerid, o.name, o.AccountId, o.Type, o.Amount from Opportunity o, o.Account a where ownerid =: UserInfo.getUserId()];

    return opp;
}

With this query I have a problem, I don't know where to get a Last Meeting Date.

I think I should create a join between Opportunity and Account. Can someone help me with this…

Best Answer

You will want to add a join to your current query. It should look something like the following.

public List<Opportunity> getOpportunity() {
List<Opportunity> opp = [SELECT o.id, o.ownerid, o.name, o.AccountId, o.Type, o.Amount o.Account.Last_Meeting_Date__c FROM Opportunity o WHERE ownerid =: UserInfo.getUserId()];

return opp;
}
Related Topic