• Damien Bell
  • NEWBIE
  • 0 Points
  • Member since 2019

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 4
    Questions
  • 2
    Replies
Hi All,

I have a Apex Class which looks like this:
 
trigger FirstTouch on FeedComment (after insert, after update){
    List<Case> updates = new List<case>();
    List<Id> feedItemList = new List<id>();
    Map<Id, User> userMap = new Map<Id, User>([SELECT Id FROM User WHERE Support_Team_Member__c = true]);
    for(FeedComment fc: trigger.new){
        if(userMap.containsKey(fc.InsertedById)){
            feedItemList.add(fc.ParentID);
        }
    }
    
    for(Case c : [Select Id from Case where Id IN (Select ParentId FROM FeedItem WHERE Id IN: feedItemList)]){
        if(c.Support_First_response_minutes__c == null && c.Case_Assigned_To_Support__c != null){
            long totalMs =     DateTime.now().getTime() - c.Case_Assigned_To_Support__c.getTime();
            totalMs *= 60000;
            updates.add(new Case(
                id = c.Id,
                Support_First_response_minutes__c = totalMs
            ));
       }
     }    
    update updates;
}


 
My test looks like this:
 
@isTest
    private class firstTouch {
        private static testMethod void firstTouch(){
            //Create a new test case
            Account a = new Account(name='test acc',phone='7777777777');
            insert a;
            Contact con = new Contact(accountid=a.id,email='test@test.com');
            con.FirstName = 'Testy';
            con.LastName = 'mcTest';
            insert con;
            Case c = new Case(Status = 'New', Priority = 'Medium', Description = 'Test', Last_Updated_By_Support__c = System.now(), Contact = con,
                                     Case_Assigned_To_Support__c = System.now(),
                                     Support_First_response_minutes__c = null );
            insert c;
            if(c.Support_First_response_minutes__c == null && c.Case_Assigned_To_Support__c!= null ){
                //Create a new feed item (Post) on the test case
                Feeditem fi = new feeditem();
                fi.Body = 'test Post on case';
                fi.Type = 'TextPost';
                //Create a new comment on the post in the case
                fi.ParentId = c.Id;
                insert fi ;
                FeedComment fc = new FeedComment(CommentBody = 'test', FeedItemID = fi.Id);
                fc.CommentType = 'TextComment';
                insert fc ;
            }
        }
    }


I've tried adding in an else as well as a 2nd method -- and I can't seem to get my coverage above 53%  Can someone help with this?
Hey there,

I've just started looking at the reporting / analytics API, and I'm not really loving how insanely difficult it is to work with.   Somehow I went from:  

User-added image

to
(GET /services/data/v44.0/analytics/reports/<id>/)
"factMap": {
        "13!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "0!T": {
            "aggregates": [
                {
                    "label": "2",
                    "value": 2
                }
            ]
        },
        "12!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "1!T": {
            "aggregates": [
                {
                    "label": "9",
                    "value": 9
                }
            ]
        },
        "10!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "11!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "2!T": {
            "aggregates": [
                {
                    "label": "5",
                    "value": 5
                }
            ]
        },
        "T!T": {
            "aggregates": [
                {
                    "label": "28",
                    "value": 28
                }
            ]
        },
        "3!T": {
            "aggregates": [
                {
                    "label": "2",
                    "value": 2
                }
            ]
        },
        "4!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "5!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "6!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "7!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "8!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        },
        "9!T": {
            "aggregates": [
                {
                    "label": "1",
                    "value": 1
                }
            ]
        }
    },

This is absolutely INSANE.  How the.... is ANYONE supposed to parse this nonsense?  The field labels are garbage and I don't see any kind of mappings explained in the file itself.

Given that the JSON response from the analytics is completely and totally unusable, is there some way to call the analytics API to generate me the csv?  I didn't see anything in the API -- but the JSON is horrid...

 
So I've created the following apex trigger, which updates a datetime field on the CASE object, which is updating the "last modified time" of the case in my sandbox -- here's the code for that.
 
trigger FeedThis on FeedComment(after insert, after update){

    List<Case> updates = new List<case>();
    List<id> userList = new List<ID>();
    List<Id> feedItemList = new List<id>();
    for(FeedComment fc: trigger.new){
        feedItemList.add(fc.FeedItemId);
        userList.add(fc.InsertedById);
    }
    Map<Id, FeedItem> feedMap = new Map<id, FeedItem>([select id,InsertedById,Visibility from feedItem where Id IN :feedItemList]);
    Map<Id, User> userMap = new Map<Id, User>([select id, usertype, name from user where ID IN :userList]);
    for(FeedComment fc: trigger.new){
        if (feedMap != null && feedMap.containsKey(fc.feedItemId) && fc.ParentId.getSObjectType() == Case.SObjectType) {
            updates.add(new Case(
                    Id = fc.ParentId,
                    Last_Chatter_Feed_Timestamp__c = System.now()
                    ));
        }
        
    }
    if(updates != null && updates.size() > 0)
    update updates;
}


I'm going to admit here that I am brand new to writing tests for SF -- and I'm sort of at a loss right now.  I'm trying to write a test for the above and didn't have much luck.   My thoughts are:

 

Given a new case is created, and a new chatter post is added, and a new comment is added to that chatter post, then the Last_Chatter_Feed_Timestamp__c > System.now() or something like that. 

Here's the code I came up with, which is horribly wrong:

 

@isTest
private class TestFeedThis {
    @isTest static void updateTimestampWithChatter(){
        //Create a new test case
        Case testCase = new Case(Status = 'New', Priority = 'Medium', Description = 'Test');
        
        //Create a new feed item (Post) on the test case
        Feeditem fi = new feeditem();
        fi.Body = 'test Post on case';
        fi.Type = 'TextPost';
        
        //Create a new comment on the post in the case
        fi.ParentId = testCase.Id;
        FeedComment fc = new FeedComment(CommentBody = 'test', FeedItemID = fi.Id);
        fc.CommentType = 'TextComment';
    }
    datetime now = System.now();
    System.assert(testCase.Last_Chatter_Feed_Timestamp__c > CreatedDate, 'true');
}
Could someone help me get this test working?

Thanks,

Hello all,

The "last modified date time"

Last Modified By <employee>, 12/20/2018 8:18 AM

Att present I have been able to make it so that the field is updated with the latest date / time on chatter POST by using a process(below)  -- but I can't seem to get it to work with chatter comments. 

The process workflow that I use for chatter post to update the field is: 
Feed Item -> New Update to Chatter Post -> Last Chatter Feed TimeStamp

Record: FeedItem.ParentID(Case)
formula NOW()

 

Is there a way to do something similar for chatter COMMENTS, as that is how my team (and my entire org for that matter) generally communicate on a case?

Thanks,

So I've created the following apex trigger, which updates a datetime field on the CASE object, which is updating the "last modified time" of the case in my sandbox -- here's the code for that.
 
trigger FeedThis on FeedComment(after insert, after update){

    List<Case> updates = new List<case>();
    List<id> userList = new List<ID>();
    List<Id> feedItemList = new List<id>();
    for(FeedComment fc: trigger.new){
        feedItemList.add(fc.FeedItemId);
        userList.add(fc.InsertedById);
    }
    Map<Id, FeedItem> feedMap = new Map<id, FeedItem>([select id,InsertedById,Visibility from feedItem where Id IN :feedItemList]);
    Map<Id, User> userMap = new Map<Id, User>([select id, usertype, name from user where ID IN :userList]);
    for(FeedComment fc: trigger.new){
        if (feedMap != null && feedMap.containsKey(fc.feedItemId) && fc.ParentId.getSObjectType() == Case.SObjectType) {
            updates.add(new Case(
                    Id = fc.ParentId,
                    Last_Chatter_Feed_Timestamp__c = System.now()
                    ));
        }
        
    }
    if(updates != null && updates.size() > 0)
    update updates;
}


I'm going to admit here that I am brand new to writing tests for SF -- and I'm sort of at a loss right now.  I'm trying to write a test for the above and didn't have much luck.   My thoughts are:

 

Given a new case is created, and a new chatter post is added, and a new comment is added to that chatter post, then the Last_Chatter_Feed_Timestamp__c > System.now() or something like that. 

Here's the code I came up with, which is horribly wrong:

 

@isTest
private class TestFeedThis {
    @isTest static void updateTimestampWithChatter(){
        //Create a new test case
        Case testCase = new Case(Status = 'New', Priority = 'Medium', Description = 'Test');
        
        //Create a new feed item (Post) on the test case
        Feeditem fi = new feeditem();
        fi.Body = 'test Post on case';
        fi.Type = 'TextPost';
        
        //Create a new comment on the post in the case
        fi.ParentId = testCase.Id;
        FeedComment fc = new FeedComment(CommentBody = 'test', FeedItemID = fi.Id);
        fc.CommentType = 'TextComment';
    }
    datetime now = System.now();
    System.assert(testCase.Last_Chatter_Feed_Timestamp__c > CreatedDate, 'true');
}
Could someone help me get this test working?

Thanks,

Hello all,

The "last modified date time"

Last Modified By <employee>, 12/20/2018 8:18 AM

Att present I have been able to make it so that the field is updated with the latest date / time on chatter POST by using a process(below)  -- but I can't seem to get it to work with chatter comments. 

The process workflow that I use for chatter post to update the field is: 
Feed Item -> New Update to Chatter Post -> Last Chatter Feed TimeStamp

Record: FeedItem.ParentID(Case)
formula NOW()

 

Is there a way to do something similar for chatter COMMENTS, as that is how my team (and my entire org for that matter) generally communicate on a case?

Thanks,