Adding a follower button to the row action

  • 1
  • Question
  • Updated 4 years ago
  • Answered
  • (Edited)
i want to add follower button to the row action ,how can i achieve that..any help..thanks
Photo of Rizvan Ansari

Rizvan Ansari

  • 382 Points 250 badge 2x thumb

Posted 5 years ago

  • 1
Photo of Emily Davis

Emily Davis, Employee

  • 3,514 Points 3k badge 2x thumb
Hi, Rizvan,

This will take some custom coding to do, but it can be done! Salesforce uses the EntittySubscription Sobject to hold information about users following records. So, create a model on EntitySubscription, with a condition where the SubscriberId equals the Id of the user viewing the page (condition type "Userinfo of page viewer"). Then, for your row action, get the Account's Id from the row by
var accountId = arguments[0].item.row;
Create a new row in the EntitySubscription model by 
var newRow = subscriptionModel.createRow({additionalConditions: [{field: 'ParentId', value: acctId}]});
subscriptionModel.save();
Of course, it will get a little more complicated to determine which accounts the user is already following, and displaying these row actions differently. This post might be helpful to you? But hopefully that's enough to get you started!

Emily
Photo of Rizvan Ansari

Rizvan Ansari

  • 382 Points 250 badge 2x thumb
Hi Emily
first of all ,thanks for the response
i don't know how to add new row in the entitysubscription model that you talk about in your response above ,please tell me that...
thanks in advance
Rizvan
(Edited)
Photo of Emily Davis

Emily Davis, Employee

  • 3,514 Points 3k badge 2x thumb
Official Response
Rizvan,
Forget what I just said about Javascript! With Skuid's new Actions Framework, you should be able to create the Follow button with no code! Here's what you need to do:

1) Create the EntitySubscription model with 2 conditions:
    (a) SubscriberId = id of the current user (Always On)
    (b) ParentId = [don't specify a value] (Filterable, default off)

Under Advanced model settings, uncheck both "Create default row if model has none" and "Load Model data on page load." Therefore, when you first load the page, this model contain no data.

2) Add your row action in the Accounts table. This row action should be type "Run Multiple Actions."

3) After specifying the action type, click on Actions.

 Add actions:
   (a) Activate & Set value of Model Condition: Set the value of the ParentId condition to the Id of the Account in the row

   (b) Create new row in Model (on your EntitySubscription model). This new row will follow your new condition on ParentId.
   (c) Save Model(s) (the EntitySubscription model).

You will notice a few things are still missing. One thing is that this row action displays whether the user is following the Account or not. Salesforce will not allow you to create more than one identical EntitySubscriptions. It will not break your page if the user clicks "Follow" on an Account he is already following, but it won't notify him either. AND the Unfollow button is a little trickier. It would be great if we could conditionally render the Follow button based on whether any rows exist in the EnititySubscription model. That would be a great idea to post in the community. It might get really positive responses from other users.

Let me know if you have any questions about this.
Emily
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,448 Points 20k badge 2x thumb
One Clarification to Emily's great write-up. 

This action framework solution is BRAND NEW.  Available only in a Skuid 5.x release.  We are now encouraging that this release only be put in sandboxes because we are still running it through its paces.  But we'd love to get your feedback on this feature and other things you can do with it. 

PS.  Emily is also using the uber-cool new Paper theme.  You need to check it out. 
Photo of Rizvan Ansari

Rizvan Ansari

  • 382 Points 250 badge 2x thumb
thanks Rob and Emily. :)
Photo of Andrew Ottaru

Andrew Ottaru

  • 412 Points 250 badge 2x thumb
Hi Emily and Rob, I have added the new model and row actions as you have listed above but nothing happens when I click to follow the record. When I go to the record I still have the option to follow. Please help. Thanks
Photo of Rob Hatch

Rob Hatch, Official Rep

  • 44,448 Points 20k badge 2x thumb
Yom,  Please read the last paragraph of Emily's post.  The Add button will always be there in this case.   That is not as nice as you'd like, but with the action framework it is about as far as we can get.