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
Doug Traster 4Doug Traster 4 

Need to only see tasks for children in Parent/Child relationship

Hi

I am trying to get only tasks/activities by children in a Parent/Child hierarchy.  I have created a visual force page to show both open and closed tasks, but I am getting other child accounts not related to the parent.  So If I have Parent account "A", and "B" and "C", which are children to "A" I only want to see B & C.  Right now I am seeing "D", "E" and "F", which related to other Parent Accounts.

Here is query I have in my constructor showing the open tasks:

tasksLimited= [Select id,whoid,whatid,subject,type, Medium_of_Activity__c, activitydate, lastmodifieddate,Account.Name, 
                   ownerid, status, priority from Task 
                   Where Account.ParentID != null And status !='completed' ORDER BY activitydate LIMIT 10];
   system.debug('taskslimited: '+taskslimited);

Any help, I have tried the WhatID, but it gives me an error, not sure how to filter this down!

 
Amit Singh 1Amit Singh 1
Hello Doug,

Use below SOQL query code.
Select id,whoid,whatid,subject, Medium_of_Activity__c, activitydate, lastmodifieddate,Account.Name, 
                   ownerid, status, priority from Task 
                   Where Account.ParentID != null And status !='completed' AND WhatId='YOUR ACCOUNT ID' ORDER BY activitydate LIMIT 10

Let me know if this helps :)

Thanks!
Amit Singh
Doug Traster 4Doug Traster 4
Amit

This doesn't do what I am wanting it to do.  I have thousands of Parent/Child Relationships.  This means I have to hard code them in?  That is not what I want, I want a declarative statement that works on all Child Accounts and only display them.  Not sure how this would work?
Amit Singh 1Amit Singh 1
Hello Doug,

You are trying to show list of all task/activity that are open using an In-Line VF page right?

Use below SQOL in your controller of VF page,
 
// Fetch Id of the account.
String accountId = apexpages.currentpage().getparameters().get('id');
Select id,whoid,whatid,subject, Medium_of_Activity__c, activitydate, lastmodifieddate,Account.Name, 
                   ownerid, status, priority from Task 
                   Where Account.ParentID != null And status !='completed' AND WhatId=:accountId ORDER BY activitydate LIMIT 10
Let me know if this resolves your problem :)

Thanks!
Amit Singh
 
Doug Traster 4Doug Traster 4
Amit

It works and I can see the tasks on the child account, but it doesn't roll up to show on the parent account.  So in my original question A is parent and B & C are Children.  I want to see tasks on A when I enter them on B or C.  Adding the Account ID makes it only show on the account you enter the task.  How do I get it to the Parent?
 
Amit Singh 1Amit Singh 1
This is because you have added "Account.ParentID != null" in your SOQL remove this part and it will work.

Cheers :)
Thanks!
Amit Singh
Doug Traster 4Doug Traster 4
Amit

But I don't want to show Parent Tasks.  Can't I do that?  Just have SOQL that will only show the child accounts in the hierarchy?