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
Hermann Oure 6Hermann Oure 6 

Apex Syntax Error


I have created an Apex class to count the number of interactions between the customer and the team when Feed Item Type = 'TextPost' or 'EmailMessageEvent'
My custom field "All Users Feed Count" increments correctly when a feed item Text Post is created but it doesn't increment for the Email Feed.
User-added image

Could someone help?

here is my code: 
public class FeedItemTriggerHandler {
    public static void countFeedItem(List<FeedItem> lstFeed){
        if(lstFeed.size() > 0){
            set<Id> setParentIds = new Set<Id>();
            for(FeedItem fd : lstFeed){
            if(setParentIds.size() > 0){
                List<Case> lstCase = [Select caseNumber,All_Users_Feed_Count__c, (Select Id,body,Type,Visibility From Feeds where Type = 'TextPost' OR Type = 'EmailMessageEvent') From Case where Id In : setParentIds];
                if(lstCase.size() > 0){
                    for(Case cs : lstCase){
                        List<CaseFeed> feeds = cs.feeds;
                        Integer count = 0;
                        for(CaseFeed cf : feeds){
                            if(cf.Visibility == 'AllUsers'){
                        cs.All_Users_Feed_Count__c = count;
                    update lstCase;

ANUTEJANUTEJ (Salesforce Developers) 
Hi Hermann,

I found the below link where in it is mentioned as of how to count the messages and the email count please have a look at the article I think it would be useful for your scenario.


In case if this was helpful in your scenario I would request you to please close the thread and mark this as best answer so that it can be useful for others in the future and also help in keeping our community clean.