function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sfdccrmsfdccrm 

implement feed item using triggers and apex class

help in implementing below design requirements using triggers and apex class

1)      Create a ‘after insert’ trigger on the FeedItem object

2)      Create an apex class that has the following method

  1. public List<User> getSubscribedUsers(FeedItem feed)

3)      Use the class in step 3 with the trigger from step 1 to generate the list of users subscribed to the case record

4)      Create any additional method in step 2 as needed

 

SamuelDeRyckeSamuelDeRycke

You may need to give a bit more info on what you're trying to build. Have you actually tried writing something yourself so far ? Do try, and let us know where specifically you are stuck.

sfdccrmsfdccrm

trigger CFeedItemCP on FeedItem (after insert, after update) {

System.debug('Attempting CFeedItemCP trigger');

if( Trigger.size > 0) {

List<FeedItem> feeds = Trigger.new;

System.debug('Processing Chatter feed item');

for( FeedItem f: feeds){

 

String objectType = CebtChatterService.getObjectType(f.ParentId);

String feedType = f.Type;

System.debug('Feed('+f.id+') of type('+feedType+') for '+objectType+' record id('+f.parentId+')');

CebtChatterService.processFeedItem(f);

}

}

}

 I have worked on so far.. i don't know how to proceed .. please suggest me .

sfdccrmsfdccrm

how can we achieve this can any one help am new

 

SamuelDeRyckeSamuelDeRycke

New is not that relevant. You've got search engines at your disposal.

 

I am still not sure what you want to build. What I have understood so far: Have a trigger on the feedItem that executes some logic only if the feedItem is on a case. Pass on the feedItem to a method in another class that returns a list of users folliwing the case. What do you want to do with those users ?

 

step 1 : build your trigger. 

you've taken a good start here. 

trigger CFeedItemCP on FeedItem(after insert, after update) {
    System.debug('Attempting CFeedItemCP trigger');
    if (Trigger.size > 0) {
        List < FeedItem > feeds = Trigger.new;
        System.debug('Processing Chatter feed item');
        for (FeedItem f: feeds) {
            String objectType = CebtChatterService.getObjectType(f.ParentId);
            String feedType = f.Type;
            System.debug('Feed(' + f.id + ') of type(' + feedType + ') for ' + objectType + ' record id(' + f.parentId + ')');
            CebtChatterService.processFeedItem(f);
        }
    }
}

 Why query if the trigger.size > 0 ? I'd expect the trigger to never be executed if there is no data .. 

You want to only perform some logic when the feeditem is related to case objects, then you need to find out how to filter that .

When building something with chatter, keep in mind the datamodel: http://developerforce.s3.amazonaws.com/website/pdfs/Chatter-cheatsheet_final.pdf

Some one else posted yesterday with a very similar request, he wanted to filter out Account related feedItems, analyse (and understand) how he's doing it, and this should help you too: http://boards.developerforce.com/t5/Apex-Code-Development/How-to-write-a-trigger-on-a-Chatter-post-on-the-Account-object/m-p/475203/message-uid/475203#U475203

 

step 2: write your class & method

I take you've done this with the CebtChatterService,but what code do you already have there ? 

 

If you look at the chatter datamodel you can see that EntitySubscription is what contains the relation between users and what they track, querieing the table you'll see that is done with the ParentId and SubscriberId. So you can simply query all users where the parentID is the parentID of your feedItem and return the list.

 

step 3: do something with your users

 

.

sfdccrmsfdccrm

can plz provide the code for the same. thanks in advance.

SamuelDeRyckeSamuelDeRycke

No, I first want you to try more on your own. Try to write things, try to understand how it works, and then post when and where in that process you are having difficulties. what lines of codes do you not understand, what do you know you want to do, but do not know to do in code. So post everything you have, and at what line you're stuck.

 

I will not just do the work for you, but I will help you learn how to do it. (limited to my own abilities).

 

 

emviousemvious

Also keep in mind that there are only certain FeedItem records that can be referenced in triggers.

 

Per the Salesforce Chatter cheatsheet, https://na1.salesforce.com/help/doc/en/salesforce_chatter_developer_cheatsheet.pdf,

 

"Triggers only support inserts and deletes. Only FeedItems of Type TextPost, 

LinkPost, and ContentPost can be inserted"

 

Based on the above verbiage only certain FeedItem types will fire on a FeedItem trigger.