2

I have situation kind of user is following certain user when they press other user profile with like button. User object have a field called followerCount field which will hold number of followers for users. when user click other user profile as follower i am calling Below @RemoteAction will create me relation between the users in entitySubscription object. Problem i am facing is when i create new record/relation on entitySubscription i wanted trigger a function so that , i want to calculate number followerCount for user. but i don't know where to write trigger for entitySubscription ? how can i achieve this functionality?

   @RemoteAction
        public static Boolean followUsers(String ParentIdStr) {

            Id ParentId = Id.valueOf(ParentIdStr);
            EntitySubscription entitySubscription = new EntitySubscription(SubscriberId = Userinfo.getUserID(),
                                                                           ParentId = ParentId,
                                                                           NetworkId = Network.getNetworkId());
            try {
                insert entitySubscription;
                return true;
            } 
            catch (DmlException e) {
                system.debug(e.getMessage());
                return false;
            }
        }

2 Answers 2

4

Currently, you can't create trigger on EntitySubscription standard object

Check this idea post https://success.salesforce.com/ideaView?id=08730000000l4s8AAA

Allow triggers on EntitySubscription standard object Apex & Visualforce

Please allow creation of an Apex trigger against the EntitySubscription object, this provides us with much greater control over who can follow who/what in chatter and is a must have feature!

So for your question

when i create new record/relation on entitySubscription i wanted trigger a function so that , i want to calculate number followerCount for user

You can place the followerCount for user logic in your remote function. After EntitySubscription insert just calculate the followerCount code

1
  • 1
    Thanks a Lot for your replay. But Problem in my case, same followUsers feature has implement all over my org , so i have to search change the each functionality , so i preferred to write a trigger without touching others codes. but i am struck because of missing feature of sales-force.
    – NITHESH K
    Commented Jul 18, 2017 at 6:59
1

You cannot write trigger on EntitySubscription.

To count the followers for a specific user, fetch the EntitySubscription records where SubscriberId = Userinfo.getUserID() and then update the User.

5
  • Problem not about writing trigger, Where can i write this trigger ? if i i want to write trigger for standard object called account, then inside "account standard object" we have option for trigger, In case custom object we have apex trigger. Now question EntitySubscription is standard object ? and there is no standard object fields specification for EntitySubscription , Should i have write trigger inside apex trigger only ?
    – NITHESH K
    Commented Jul 18, 2017 at 5:43
  • Yes you need to write the trigger in Apex Trigger. Go to Setup > Apex Trigger
    – Ankita
    Commented Jul 18, 2017 at 5:48
  • i went to create new trigger through developer Console , its asking for Name And SObject, SObject is drop down list SObject's . But in that list EntitySubscription object not appears .
    – NITHESH K
    Commented Jul 18, 2017 at 6:13
  • trigger trigName on EntitySubscription (after insert){ for(EntitySubscription es: Trigger.new){ //logic } } its throw me error " SObject type does not allow triggers: EntitySubscription "
    – NITHESH K
    Commented Jul 18, 2017 at 6:15
  • Thanks a Lot for your replay. But Problem in my case, same followUsers feature has implement all over my org , so i have to search change the each functionality , so i preferred to write a trigger without touching others codes. but i am struck because of missing feature of sales-force.
    – NITHESH K
    Commented Jul 18, 2017 at 7:00

You must log in to answer this question.

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