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
pratap narwalpratap narwal 

How to populate the task in open activites Related List ( Not a Master Detail Relationship).

Hi All,
I have 3 obects having Master detail relationship with below flow:

Account---> CustomObject1---> CustomObject2

When i create a task on Customobject2, i want to show it on Open activities related list on Account object. This is not  possible using standard salesforce feature.

As a workaround i am thinking of below approach.


-Create a inline visualforce page on account page that contains all the task which comes under the specified account.

 But i am not getting the way to retrieve the tasks which are created for CustomObject2 and related to a specified Account. How can i acheive this?

Please let me know if my approach is correct or suggest any other alternative.


Thanks in Advance
Vivek_PatelVivek_Patel
Hi Pratap,

Following code gives the list of all open activites on the Account's contact, in the similar way you can get the list of activities for your requirement.
 
List<Account> acc = [SELECT Id, Name, (SELECT Id FROM Contacts) FROM Account];
Set<Id> contIdSet = new Set<Id>();
for(Account accObj : acc) {
    for(Contact cont : accObj.contacts) {
        contIdSet.add(cont.Id);
    }
}
List<Contact> contList = [SELECT Id, (SELECT Id FROM OpenActivities) FROM COntact WHERE Id IN : contIdSet];
System.debug(contList[0].OpenActivities);



Regards,
Vivek Patel.

Please like or mark this as best answer if this answers your question to help others find better answer and improve the quality of developer forum.