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
Malik Butler 5Malik Butler 5 

Public List

I'm trying to create a component that shows related activity on the account page. But it's only showing the last object. Any ideas on how to fix this? Also is there a way to add the chatter feed?


public with sharing class CaseActivityController {
    
    public List<Task> lstTask {get;set;}
    
    public CaseActivityController(ApexPages.StandardController std) 
    {
        Id AccountId = std.getId(); //Get AccountId
        
        //Query on Case
        Map<Id, Case> mapIdToCase = new Map<Id,Case>([Select Id from Case where AccountId =: AccountId]);
        
        //Query on Case Activity 
        lstTask = new List<Task>([SELECT CallType,Status,Subject,WhatId,ActivityDate,Description FROM Task WHERE WhatId IN: mapIdToCase.keyset() ORDER BY ActivityDate]);
        
        //Query on Contact
        Map<Id, Contact> mapIdToContact = new Map<Id,Contact>([Select Id from Contact where AccountId =: AccountId]);
        
        //Query on Contact Activity 
        2ndTask = new List<Task>([SELECT CallType,Status,Subject,WhatId,ActivityDate,Description FROM Task WHERE WhatId IN: mapIdToContact.keyset() ORDER BY ActivityDate]);
         
        //Query on Opportunity
        Map<Id, Opportunity> mapIdToOpportunity = new Map<Id,Opportunity>([Select Id from Opportunity where AccountId =: AccountId]);
        
        //Query on Opportunity Activity 
        3rdTask = new List<Task>([SELECT CallType,Status,Subject,WhatId,ActivityDate,Description FROM Task WHERE WhatId IN: mapIdToOpportunity.keyset() ORDER BY ActivityDate]);
    }
}
shaik murthujavalishaik murthujavali
Hi,
Here you did not created object for 2ndTask and 3rdTask. Add 2ndTask and 3rdTask to lstTask.

In the background, once an object is enable for feed tracking, Salesforce will create new object end with suffix Feed (for Standard object) or _Feed (for Custom object).
Select Id, ParentId, Type, Title, Body, CommentCount, LikeCount, LinkUrl, RelatedRecordId, ContentFileName, ContentSize, ContentType From Object1__Feed

If it works fro you pls mark it as a best answer so that it helps others too.
Thanks.