1. How can I retrieve all Note records for a particular Account using SOQL?
  2. How can I retrieve all Opportunity records for a particular Contact using SOQL?
  • 2
    What have you already tried? Commented Oct 6, 2017 at 11:43

2 Answers 2


to be more familiar with such queries read next first, second

How to retrieve all the Note of a particular Account using SOQL query

Here are child relationship helps

select Id, (
    select Id, Body
    from Notes
from Account
where Id = :desiredAccountId

How to retrieve all the opportunity of a particular Contact using SOQL Query

select Id
from Opportunity
where AccountId in (
    select AccountId
    from Contact
    where Id = :desiredContactId
  • This will only work if there's a relationship established as a field in the outer object... or so it seems. If there's only a child relationship established (for cascading deletes, for example), and not an explicit named relationship, it's considered an "arbitrary join" and is not supported in SOQL.
    – J.D. Pace
    Commented Dec 21, 2019 at 4:45

For getting Notes you can use next query:

SELECT Id, Title 
FROM Note 
WHERE parentid = :account.Id

For Opportunities related to Contact - if you use OpportunityContactRole object for connecting these objects, you can use such query:

SELECT Id, Name,
    (SELECT Contact.Name
     FROM OpportunityContactRoles
     WHERE ContactId = :contact.Id)
FROM Opportunity

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