0

I'm trying to get the Leads columns from the Account object.

This is the type of query I want to run, but it doesn't work:

SELECT Account.Name, (SELECT Name FROM Account.Leads) FROM Account 

If I describe the account object, the childRelationships of account has a lead but no relationshipName. Is there a way to perform this query and somehow use the ConvertedAccountId even though the relationshipName is missing?

{ "cascadeDelete": false, "childSObject": "Lead", "deprecatedAndHidden": false, "field": "ConvertedAccountId", "junctionIdListNames": [], "junctionReferenceTo": [], "relationshipName": null, "restrictedDelete": false } 

Doing this works with contacts

SELECT Account.Name, (SELECT Name FROM Account.Contacts) FROM Account 
{ "cascadeDelete": true, "childSObject": "Contact", "deprecatedAndHidden": false, "field": "AccountId", "junctionIdListNames": [], "junctionReferenceTo": [], "relationshipName": "Contacts", "restrictedDelete": false } 

1 Answer 1

0

The relationship is not available in SOQL for some reason.

A possible workaround would be to query the leads directly via the lookup relationship like this:

SELECT Id, LastName, FirstName, MiddleName, Name, Company FROM Lead WHERE ConvertedAccountId IN (SELECT Id FROM Account) 

As a bonus and a good to know, child queries are limited to three times the parent queries resulting child records, this query is not limited in such a way.

2
  • Child queries are limited to three times the parent queries, not "100 resulting child records." See Apex Governor Limits. Commented Jun 5, 2024 at 15:50
  • Thank you! we learn something new every day ;) Commented Jun 6, 2024 at 7:46

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.