1

Custom field is created for Public Chatter Posts and Unread Public Chatter Posts

trigger CountChatterPostsOnCase on FeedItem (before insert, after insert) {
    String caseKeyPrefix = Case.sObjectType.getDescribe().getKeyPrefix();
    set<ID> caseIDs = new set<ID>();
    for (FeedItem f : trigger.new){
        String parentId = f.parentId;
        if (parentId != null && parentId.startsWith(caseKeyPrefix) ){
            caseIDs.add(f.parentId);
        }
    }
    if(!caseIDs.IsEmpty()){
        list<case> cslist =[Select F1 ,F2  from Case where id = :caseIDs];
        for (case cs:cslist) {
            cs.F1 = cs.F1 + 1;
            cs.F2 = cs.F2 + 1;
        }
        update cslist;
    }
}

Am getting error Arithmetic expressions must use numeric arguments .. can you guide me which fiels i need to take from case object to increment feeditems on posted.

Test class for the below trigger @istest public class CountChatterPostsOnCase{ public static testmethod void () {

Can you anyone guide me how to implement and getting lots error while writing..

0

This is a guess as you haven't post the line on which the error is occurring, but I'm guessing it's this:

cs.Id = cs.Id + 1;

Which isn't going to work as Apex doesn't know how to increment IDs.

Try something like this:

for (Integer i = 0; i < cslist.size(); i++) {

    cs.Id = cslist[i+1].Id;
    cs.Case_Opened_Hour__c = cs.Case_Opened_Hour__c + 1;

}
  • can you guide me which field i need to get frm case object which is realted to chatterfeed items .. so that i can increment posted on feed items. – satish Aug 20 '14 at 17:06
  • After this execute your code am getting this error Invalid type: Int – satish Aug 20 '14 at 17:09
  • 1
    try Integer instead of Int. – Davin Casey Aug 20 '14 at 17:14
  • No problem, please mark this question as answered if you're happy with the solution. – Davin Casey Aug 27 '14 at 17:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.