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;
}
}
Best Answer
Currently, you can't create trigger on EntitySubscription standard object
Check this idea post https://success.salesforce.com/ideaView?id=08730000000l4s8AAA
So for your question
You can place the followerCount for user logic in your remote function. After EntitySubscription insert just calculate the followerCount code