Reputation: 71
I have related list called "Approvers" in opportunity object.
And I created few dummy records in approvers.
I am trying to fetch all those related list record associated with opportunity.
For eg : Select all approvers where opportunity id="some-id";
Any suggestion would be really appreciated.
Upvotes: 0
Views: 6979
Reputation: 11
There are several methods:
As eyescream pointed out, a separate query can fetch all approvers for a specific opportunity.
You can use a subquery: SELECT Id, Name, (SELECT Id, Name FROM Approvers__r) FROM opportunity.
In Visualforce pages with a standard controller, you can use the apex:relatedList component to automatically show the list as it would have shown in the page layout.
Upvotes: 1
Reputation: 19622
SELECT Id, Name
FROM Approver__c
WHERE Opportunity__c = '...'
Should be a good start.
Depends how your custom object is called exactly and what's the name of the "Lookup(Opportunity)" field.
You should have at least quick look at https://developer.salesforce.com/docs/atlas.en-us.soql_sosl.meta/soql_sosl/sforce_api_calls_soql.htm
Or maybe Trailhead self-learning courses?
Upvotes: 1