Amit
Amit

Reputation: 71

How to fetch all the records in related list

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

Answers (2)

user7038758
user7038758

Reputation: 11

There are several methods:

  1. As eyescream pointed out, a separate query can fetch all approvers for a specific opportunity.

  2. You can use a subquery: SELECT Id, Name, (SELECT Id, Name FROM Approvers__r) FROM opportunity.

  3. 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

eyescream
eyescream

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

Related Questions