+ Start a Discussion

How to query the Account table and include Lead table fields

In another post, I saw how to query from the Lead table to the Account table like the following:

select firstname, convertedaccount.lastname from lead where firstname = 'John'

the firstname field is from the Lead table and the lastname field is the Account table.

How can I do the reverse where I want to go from the Account table (knowing the Account.lastname = 'Smith') and pull the firstname field from the Lead table and the lastname field from the Account table.  I don't want to do this with two queries but like above, only use one query.

As fas as I know, the only way to accomplish this by using the inner query. However, we are not able to locate the correct relationship name between Account(Parent) and Lead(child). Following I tried to run from dev console, but it is not working. The relationship name between Account and Lead is ConvertedAccount:

select Id, (select Id from ConvertedAccount) from Account
sumit singh 37sumit singh 37
No we cannot query the fields of lead object from Account query.  as Account is not related to lead , but lead have fields like ConvertedAccount, Convertedopportunity