You need to sign in to do that
Don't have an account?
Hermann Oure 6
Iterate through Map to increment count
Hi,
My apex code doesn't not increment the count. Can't find out Why.
Could someone help?
Thanks
Apex class:
My apex code doesn't not increment the count. Can't find out Why.
Could someone help?
Thanks
Apex class:
public class FeedItemTriggerHandler { public static void countFeedItem(List<FeedItem> lstFeed){ set<id> relatedCasesIds = new set<id>(); for(FeedItem fd : lstFeed) { if (fd.type =='TextPost')relatedCasesIds.add(fd.ParentId); } Map<Id, case> relatedCases = new Map<Id, case> ([Select id, caseNumber,All_Users_Feed_Count__c FROM case where id in: relatedCasesIds]); List<case> casesToUpdate = new List<case>(); integer count = 0; for(case c:relatedCases.values()) { for(FeedItem fd : lstFeed) { if (fd.type =='TextPost' && fd.Visibility =='AllUsers' && fd.ParentId == c.id) { count+=1; } } c.All_Users_Feed_Count__c = count; count = 0; casesToUpdate.add(c); } if(casesToUpdate.size() > 0) update casesToUpdate; } }Trigger:
trigger FeedItemTrigger on FeedItem (after insert,before delete) { if(Trigger.isAfter){ if(Trigger.isInsert){ FeedItemTriggerHandler.countFeedItem(Trigger.new); } } else if(Trigger.isBefore){ if(Trigger.isDelete){ FeedItemTriggerHandler.countFeedItem(Trigger.old); } } }
Is the value being the same or is it changing to any other value??Also, can you try checking if the flow is going into the loop,because I tried debugging a statement inside but I was not able to print it.
Regards,
Anutej
When I create a case the field All_Users_Feed_Count__c counts 1. But when I add a text post in the case feed. The field All_Users_Feed_Count__c doesn't increment.
What I am trying to do is anytime there is a text post from the case feed. The count increases on the field All_Users_Feed_Count__c.
But currently it remains to 1.
And when I make a text post to internal users, the field All_Users_Feed_Count__c goes back to 0.
Not sure how to fix it.
This might be late reply but still giving apex class code about how I think it should be:
Hope it help someone :)