function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
steven75steven75 

Help with SOQL Query

Hi,

 

I try to list all the account.Name, Opportunity.Name, CaseNumber, and Tasks that associated with the Case.

 

I did somethink wrong in my query which only list account.Name, Opportunity.Name, CaseNumber, but NOT tasks. 

 

select account.Name, (select Opportunity.Name from Account.Opportunities),  (Select CaseNumber from Cases), (select Task.Subject from Tasks)  from Account

 

Please help,

Ispita_NavatarIspita_Navatar

Your query is perfectly fine , I ran it I got all the 4 types of objects in the resultset.

Tasks of Account only will be enlisted that is tasks whose Whatid is set to a AccountId.

 

Try running it again by creating soem fresh test data.

 

Did this answer your question? If not, let me know what didn't work, or if so, please mark it solved.

 

steven75steven75

Thanks for the response,

 

Maybe my query is fine, but I didn't get the result I needed, maybe I need different Join query method to get what I need.  What I did was created Cases under Opportunities, then created Tasks under Case, so one case can have multiple tasks associated with it. 

 

So I was trying to list all the Opportunities, Cases, and Tasks, but I couldn't get that far to the Tasks.  I would like the result list looks like this format:

 

1. Oppportunit#1, Case#1, Task#1

2. Oppportunit#1, Case#1, Task#2

3. Oppportunit#1, Case#1, Task#3

3. Oppportunit#2, Case#1, Task#1

3. Oppportunit#2, Case#1, Task#2

kprkpr

 

 

select c.Opportunity.Account.Name,c.Opportunity.Name,(select subject from Tasks),CaseNumber from Case c

 

I haven't tested it, but developed it from your scenario. It should work. give it a try