• Jakob Berntsson
  • NEWBIE
  • 10 Points
  • Member since 2018

  • Chatter
    Feed
  • 0
    Best Answers
  • 1
    Likes Received
  • 0
    Likes Given
  • 3
    Questions
  • 3
    Replies
Hi!

I'm trying to create a Flow for merging cases. The idea is simply to update the related records that can be re-parented, and copy the rest. We have "Enable Case Feed Actions and Feed Items" enabled, so all emails appear as FeedItem records with type EmailMessageEvent.

My problem is this: for emails I'm copying the EmailMessage record and the FeedItem records with type EmailMessageEvent. The problem is that I can't seem to find how these two records are related. The FeedItem record contains no reference to the EmailMessage record, and vice versa.

I'm thinking if there might be some other object that contains references to both the EmailMessage and FeedItem, and that is what ties them together, but I have yet been able to find something like this in the Object Reference.

Can someone help me find out what I'm missing here? Thanks in advance!

Best regards,
Jakob Berntsson
Hi,

In order to change what the tabs in Service Console in Lightning say for cases, I have implemented a Lightning Component + Apex classes after the instructions on the following page:

https://rajvakati.com/2018/11/13/lightning-console-set-tab-label-dynamically/

The only difference between his and my code is that I'm using the Subject field rather than the Origin field. Otherwise my "version" is identical.

While this mostly works, I've noticed that when one of the "Update a Record" actions in the case are used, the case label of the active tab sometimes incorrectly is set to another tab. This doesn't happen every time, but often enough to cause confusion among the support agents.

See example:User-added image

The action used for this test looks like this:
User-added image

How can I stop this happening? Is it because the doInit function isn't called often enough in the Component? What would I need to do to cover the scenario above as well?

Thanks in advance!

Best regards,
Jakob Berntsson
Hi! I'm trying to make a trigger that sets a Case's status to "Open" when a FeedComment is inserted or updated. While the trigger works fine when I've tested it in real-world cases in my sandbox, I have not been able to get any test case working.

Here's the trigger:
trigger UpdateStatus on FeedComment (after insert, after update) {
    
    List<Case> caselist = new List<Case>();
    List<Case> casestoupd = new List<Case>();
    List<Id> caseids = new List<Id>();
    
    for(FeedComment f:Trigger.New) {
        if (f.ParentId.getSObjectType() == Case.SObjectType) {
            caseids.add(f.ParentId);
        }
    }
    
    try {
        caselist = [Select Id, Status from Case where Id IN :caseids];
    }
    catch(Exception e) {
        caselist = null;
    }
    
    for(Case c:caselist) {
        c.Status = 'Open';
        casestoupd.add(c);
    }
    
    List<Database.SaveResult> updateResults = Database.update(casestoupd,False);
}

And here's the test:
@isTest
private class UpdateStatus_UnitTest {
    
    static testMethod void testTrigger() {
        
        Case c = new Case(Subject='Test Case', Status = 'New');
        insert c;
        
        test.startTest();
        
        FeedItem f = new FeedItem(ParentId=c.Id, Body='Test Post');
        insert f;
        
        FeedComment fc = new FeedComment(CommentBody='Test Comment',FeedItemId = f.Id);
        insert fc;
        
        System.assertEquals('Closed', c.Status);
        
        test.stopTest();
        
    }
}

The problem seems to be that FeedComment's ParentId field isn't writable. When I try to print out fc.ParentId it just returns null, and because of this the System.assertEquals test fails.

Really appreciate any help I can get on this. Thanks in advance!
Hi!

I'm trying to create a Flow for merging cases. The idea is simply to update the related records that can be re-parented, and copy the rest. We have "Enable Case Feed Actions and Feed Items" enabled, so all emails appear as FeedItem records with type EmailMessageEvent.

My problem is this: for emails I'm copying the EmailMessage record and the FeedItem records with type EmailMessageEvent. The problem is that I can't seem to find how these two records are related. The FeedItem record contains no reference to the EmailMessage record, and vice versa.

I'm thinking if there might be some other object that contains references to both the EmailMessage and FeedItem, and that is what ties them together, but I have yet been able to find something like this in the Object Reference.

Can someone help me find out what I'm missing here? Thanks in advance!

Best regards,
Jakob Berntsson
Hi!

I'm trying to create a Flow for merging cases. The idea is simply to update the related records that can be re-parented, and copy the rest. We have "Enable Case Feed Actions and Feed Items" enabled, so all emails appear as FeedItem records with type EmailMessageEvent.

My problem is this: for emails I'm copying the EmailMessage record and the FeedItem records with type EmailMessageEvent. The problem is that I can't seem to find how these two records are related. The FeedItem record contains no reference to the EmailMessage record, and vice versa.

I'm thinking if there might be some other object that contains references to both the EmailMessage and FeedItem, and that is what ties them together, but I have yet been able to find something like this in the Object Reference.

Can someone help me find out what I'm missing here? Thanks in advance!

Best regards,
Jakob Berntsson
Hi,

In order to change what the tabs in Service Console in Lightning say for cases, I have implemented a Lightning Component + Apex classes after the instructions on the following page:

https://rajvakati.com/2018/11/13/lightning-console-set-tab-label-dynamically/

The only difference between his and my code is that I'm using the Subject field rather than the Origin field. Otherwise my "version" is identical.

While this mostly works, I've noticed that when one of the "Update a Record" actions in the case are used, the case label of the active tab sometimes incorrectly is set to another tab. This doesn't happen every time, but often enough to cause confusion among the support agents.

See example:User-added image

The action used for this test looks like this:
User-added image

How can I stop this happening? Is it because the doInit function isn't called often enough in the Component? What would I need to do to cover the scenario above as well?

Thanks in advance!

Best regards,
Jakob Berntsson
Hi! I'm trying to make a trigger that sets a Case's status to "Open" when a FeedComment is inserted or updated. While the trigger works fine when I've tested it in real-world cases in my sandbox, I have not been able to get any test case working.

Here's the trigger:
trigger UpdateStatus on FeedComment (after insert, after update) {
    
    List<Case> caselist = new List<Case>();
    List<Case> casestoupd = new List<Case>();
    List<Id> caseids = new List<Id>();
    
    for(FeedComment f:Trigger.New) {
        if (f.ParentId.getSObjectType() == Case.SObjectType) {
            caseids.add(f.ParentId);
        }
    }
    
    try {
        caselist = [Select Id, Status from Case where Id IN :caseids];
    }
    catch(Exception e) {
        caselist = null;
    }
    
    for(Case c:caselist) {
        c.Status = 'Open';
        casestoupd.add(c);
    }
    
    List<Database.SaveResult> updateResults = Database.update(casestoupd,False);
}

And here's the test:
@isTest
private class UpdateStatus_UnitTest {
    
    static testMethod void testTrigger() {
        
        Case c = new Case(Subject='Test Case', Status = 'New');
        insert c;
        
        test.startTest();
        
        FeedItem f = new FeedItem(ParentId=c.Id, Body='Test Post');
        insert f;
        
        FeedComment fc = new FeedComment(CommentBody='Test Comment',FeedItemId = f.Id);
        insert fc;
        
        System.assertEquals('Closed', c.Status);
        
        test.stopTest();
        
    }
}

The problem seems to be that FeedComment's ParentId field isn't writable. When I try to print out fc.ParentId it just returns null, and because of this the System.assertEquals test fails.

Really appreciate any help I can get on this. Thanks in advance!