0

We have Email-To-Case configured, and once a case is created (case origin = email), the incoming EmailMessage is saved within the 'Case Description' field, and also create a 'feed item': enter image description here

This allows our Support agent to reply with the Email Composer, and the original EmailMessage appears in the Email Thread.

I would like to achieve the same functionality with other originated cases, such as 'Web' (via Web-To-Case), Portal, etc. These cases are not creating a 'feed item', and only sets the 'Case Description' field: enter image description here

I know that I can use the 'Case Description' as a merge field with an Email Template when replying, but I wanted to understand if there is a better solution, which might involve creating the 'feed item' (Trigger perhaps?).

Thank you.

1 Answer 1

1

With your requirement, it seems you need to write a trigger on case object, and check "Case Origin". Sample trigger code would be

trigger CaseTrg on Case (after Insert) {
    List<FeedItem> FeedItems = new List<FeedItem>();
    for(Case c: trigger.new)
    {
        // don't check other stuff if the origin is Email-to-Case as it is already running tip-top
        if (c.Case_Origin != 'Email')
        {
            if (c.Case_Origin == 'Web' OR c.Case_Origin == 'Portal' ) // add more cases with OR as per your need
            {
                //create and insert Feeditem
                FeedItem post = new FeedItem();
                post.Body = 'blah.blah....';
                post.ParentId = [ID_OF_CASE];
                post.Title = '[Case Subject? or any other Case related field you feel suitable]';
                FeedItems.add(post);
            }
        }
    }   
    if(FeedItems.size() > 0) Insert FeedItems;
}
4
  • Thanks Mahmood. I implemented the trigger, and added 'c.ParentId' as the Case Parent ID, but am receiving an error upon case creation 'Required fields are missing: [ParentId]'. Below is the feeditem creation portion: FeedItem post = new FeedItem(); post.Body = c.Description; post.ParentId = c.ParentId; post.Title = c.Subject; FeedItems.add(post);
    – iDog
    Feb 25, 2017 at 15:35
  • c.parentid is referring to the parent case. You need to make it c.id Which refers to case id.
    – Mahmood
    Feb 25, 2017 at 15:38
  • Thanks. I changed to "post.ParentId = 'c.ParentId';" and now receive an error: "Invalid id: c.ParentId".
    – iDog
    Feb 25, 2017 at 15:45
  • 1
    Use post.parentid = c.id
    – Mahmood
    Feb 25, 2017 at 15:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .