Mass Action Create Row Chatter Subscription

  • 1
  • Question
  • Updated 1 year ago
  • Answered
I have a table based off of the opportunity object.  From the table, I would like to have the functionality to subscribe and unsubscribe to records chatter feeds through mass actions.

I have been able to get the unsubscribe functionality to work as intended, where the mass action removes the user as a follower.  However, for the add functionality, I am unable to make it work.  In the attached screen shots is the actions attached to the subscribe (follow) and unsubcribe (unfollow) actions.
Photo of David Garrity

David Garrity

  • 856 Points 500 badge 2x thumb

Posted 1 year ago

  • 1
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
David,

In your 'follow' actions, do you set the SubscriberId?

Thanks,

Bill
Photo of David Garrity

David Garrity

  • 856 Points 500 badge 2x thumb
The follow actions do not set the subscriberId, however, the entitysubscription model is always keeping the subscriberId to running user through a condition.
Photo of Bill McCullough

Bill McCullough, Champion

  • 12,436 Points 10k badge 2x thumb
David,

Take a look at this example page based on Opportunities.  I used a model to get the current user's Id and then set the subscriber id condition to use the Id from the model rather than the running user id.

Note that this page also demonstrates a custom render for the Opportunity Feed.

Thanks,

Bill

<skuidpage unsavedchangeswarning="yes" personalizationmode="server" useviewportmeta="true" showsidebar="true" showheader="true" tabtooverride="Opportunity">
    <models>
        <model id="CurrentUser" limit="1" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="User">
            <fields>
                <field id="Id"/>
                <field id="Name"/>
            </fields>
            <conditions>
                <condition type="userinfo" value="" field="Id" operator="=" enclosevalueinquotes="true" userinfotype="userid"/>
            </conditions>
            <actions/>
        </model>
        <model id="Opportunity" limit="100" query="true" createrowifnonefound="false" datasource="salesforce" sobject="Opportunity" type="">
            <fields>
                <field id="Name"/>
                <field id="CreatedDate"/>
                <field id="Feeds" type="childRelationship" limit="1" orderby="CreatedDate DESC">
                    <fields>
                        <field id="Body"/>
                        <field id="Title"/>
                    </fields>
                    <conditions/>
                </field>
                <field id="PartnerAccountId"/>
                <field id="PartnerAccount.Name"/>
                <field id="Id"/>
                <field id="OpportunityFeed" uionly="true" displaytype="TEXTAREA" label="Opportunity Feed" ogdisplaytype="TEXT" length="2500"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
        <model id="EntitySubOpp" limit="200" query="false" createrowifnonefound="false" datasource="salesforce" type="" sobject="EntitySubscription">
            <fields>
                <field id="ParentId"/>
                <field id="Parent.Name"/>
                <field id="SubscriberId"/>
                <field id="Subscriber.Name"/>
            </fields>
            <conditions/>
            <actions/>
        </model>
        <model id="EntitySubOppDrawer" limit="200" query="false" createrowifnonefound="false" datasource="salesforce" type="" sobject="EntitySubscription">
            <fields>
                <field id="ParentId"/>
                <field id="Parent.Name"/>
                <field id="SubscriberId"/>
                <field id="Subscriber.Name"/>
            </fields>
            <conditions>
                <condition type="fieldvalue" value="" enclosevalueinquotes="true" field="ParentId" fieldtargetobjects="Account,Asset,Campaign,Case,CollaborationGroup,Contact,ContactAccountJunction__c,ContentDocument,Contract,Dashboard,DashboardComponent,Event,Ghost__c,Goal,Lead,Metric,ObjectFromEmailAcceptedFields__c,ObjectFromEmailDefaultFields__c,Opportunity,Order,OrderItem,Product2,Quote,Report,SDOC__SDField__c,SDOC__SDJob__c,SDOC__SDRelationship__c,SDOC__SDTemplate__c,SDOC__SDoc__c,SDOC__SDocsSettings__c,Site,Solution,Sort_Order__c,Store__c,Task,Topic,Trove__TroveConfiguration__c,User,WorkCoaching,WorkFeedbackRequest,WorkPerformanceCycle,abc__c,cdrive__AWS_Account__c,cdrive__AWS_S3_Configurations__c,cdrive__AWS_Set_UP__c,cdrive__Cloud_Files__c,skuid__Auth_Provider__c,skuid__Component_Pack__c,skuid__Encryption_Settings__c,skuid__Image__c,skuid__Model_Service_Adapter__c,skuid__Model_Service_Credential__c,skuid__Model_Service__c,skuid__Page_Assignment__c,skuid__Page_Interaction__c,skuid__Page_Version__c,skuid__Page__c,skuid__Personalization_Settings__c,skuid__Preferences__c,skuid__Theme__c,z_ChildRelationship__c,z_FieldDescription__c,z_MetaDumpSetting__c,z_SObjectDescription__c,z_SchemaTemp__c" state="filterableoff" inactive="true" name="ParentIdDrawer"/>
            </conditions>
            <actions/>
        </model>
        <model id="OpportunityFeed" limit="200" query="true" createrowifnonefound="false" datasource="salesforce" type="" sobject="OpportunityFeed" orderby="CreatedDate DESC">
            <fields>
                <field id="Body"/>
                <field id="ParentId"/>
                <field id="Parent.Name"/>
            </fields>
            <conditions>
                <condition type="modelmerge" value="" field="ParentId" fieldtargetobjects="Opportunity" operator="in" model="Opportunity" enclosevalueinquotes="true" mergefield="Id" novaluebehavior="noquery"/>
            </conditions>
            <actions/>
        </model>
    </models>
    <components>
        <pagetitle model="Opportunity" uniqueid="sk-K0ovG-83">
            <maintitle>
                <template>{{Model.labelPlural}}</template>
            </maintitle>
            <subtitle>
                <template>Home</template>
            </subtitle>
            <actions>
                <action type="savecancel" uniqueid="sk-K0ovF-82"/>
            </actions>
        </pagetitle>
        <skootable showconditions="true" showsavecancel="false" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" createrecords="true" model="Opportunity" mode="read" allowcolumnreordering="true" uniqueid="sk-K0ove-93" emptysearchbehavior="query">
            <fields>
                <field id="Name" hideable="true" allowordering="true" uniqueid="fi-K0nv4-243"/>
                <field id="OpportunityFeed" hideable="true" uniqueid="fi-SCWYr-177" valuehalign="" type="CUSTOM" snippet="renderOpportunityFeed"/>
                <field id="CreatedDate" hideable="true" allowordering="true" uniqueid="fi-K0nv4-244" valuehalign="" type=""/>
                <field id="PartnerAccountId" hideable="true" uniqueid="fi-K4KGG-338" valuehalign="" type="" optionsource="" pagesize="5" tokenizesearch="true">
                    <searchfields/>
                </field>
            </fields>
            <rowactions>
                <action type="edit"/>
                <action type="delete"/>
                <action type="drawer" label="Show Subscriptions" icon="sk-icon-listview" openicon="sk-icon-close">
                    <drawer title="Drawer Area" width="90%" closehandle="true">
                        <components>
                            <skootable showconditions="true" showsavecancel="true" showerrorsinline="true" searchmethod="server" searchbox="true" showexportbuttons="false" pagesize="10" alwaysresetpagination="false" createrecords="true" model="EntitySubOppDrawer" buttonposition="" mode="read" allowcolumnreordering="true" responsive="true" uniqueid="sk-KYzM5-383">
                                <fields>
                                    <field id="ParentId" hideable="true" uniqueid="fi-KZ0Th-399"/>
                                    <field id="SubscriberId" hideable="true" uniqueid="fi-KZ0Th-400"/>
                                </fields>
                                <rowactions>
                                    <action type="edit"/>
                                    <action type="delete"/>
                                </rowactions>
                                <massactions usefirstitemasdefault="true">
                                    <action type="massupdate"/>
                                    <action type="massdelete"/>
                                </massactions>
                                <views>
                                    <view type="standard"/>
                                </views>
                                <conditions>
                                    <condition type="contextrow" field="ParentId" mergefield="Id" operator="=" fieldtargetobjects="Account,Asset,Campaign,Case,CollaborationGroup,Contact,ContactAccountJunction__c,ContentDocument,Contract,Dashboard,DashboardComponent,Event,Ghost__c,Goal,Lead,Metric,ObjectFromEmailAcceptedFields__c,ObjectFromEmailDefaultFields__c,Opportunity,Order,OrderItem,Product2,Quote,Report,SDOC__SDField__c,SDOC__SDJob__c,SDOC__SDRelationship__c,SDOC__SDTemplate__c,SDOC__SDoc__c,SDOC__SDocsSettings__c,Site,Solution,Sort_Order__c,Store__c,Task,Topic,Trove__TroveConfiguration__c,User,WorkCoaching,WorkFeedbackRequest,WorkPerformanceCycle,abc__c,cdrive__AWS_Account__c,cdrive__AWS_S3_Configurations__c,cdrive__AWS_Set_UP__c,cdrive__Cloud_Files__c,skuid__Auth_Provider__c,skuid__Component_Pack__c,skuid__Encryption_Settings__c,skuid__Image__c,skuid__Model_Service_Adapter__c,skuid__Model_Service_Credential__c,skuid__Model_Service__c,skuid__Page_Assignment__c,skuid__Page_Interaction__c,skuid__Page_Version__c,skuid__Page__c,skuid__Personalization_Settings__c,skuid__Preferences__c,skuid__Theme__c,z_ChildRelationship__c,z_FieldDescription__c,z_MetaDumpSetting__c,z_SObjectDescription__c,z_SchemaTemp__c"/>
                                </conditions>
                            </skootable>
                        </components>
                        <beforeload>
                            <action type="setCondition" model="EntitySubOppDrawer" condition="ParentIdDrawer" value="{{Id}}"/>
                            <action type="requeryModel" model="EntitySubOppDrawer" behavior="loadmore"/>
                        </beforeload>
                    </drawer>
                </action>
            </rowactions>
            <massactions usefirstitemasdefault="true">
                <action type="multi" label="Subscribe to {{Name}}" icon="sk-icon-magic">
                    <actions>
                        <action type="blockUI" message="Subscribing"/>
                        <action type="createRow" model="EntitySubOpp" appendorprepend="prepend" defaultmodefornewitems="edit" affectedrows="context">
                            <defaults>
                                <default type="fieldvalue" field="ParentId" fieldtargetobjects="Account,Asset,Campaign,Case,CollaborationGroup,Contact,ContactAccountJunction__c,ContentDocument,Contract,Dashboard,DashboardComponent,Event,Ghost__c,Goal,Lead,Metric,ObjectFromEmailAcceptedFields__c,ObjectFromEmailDefaultFields__c,Opportunity,Order,OrderItem,Product2,Quote,Report,SDOC__SDField__c,SDOC__SDJob__c,SDOC__SDRelationship__c,SDOC__SDTemplate__c,SDOC__SDoc__c,SDOC__SDocsSettings__c,Site,Solution,Sort_Order__c,Store__c,Task,Topic,Trove__TroveConfiguration__c,User,WorkCoaching,WorkFeedbackRequest,WorkPerformanceCycle,abc__c,cdrive__AWS_Account__c,cdrive__AWS_S3_Configurations__c,cdrive__AWS_Set_UP__c,cdrive__Cloud_Files__c,skuid__Auth_Provider__c,skuid__Component_Pack__c,skuid__Encryption_Settings__c,skuid__Image__c,skuid__Model_Service_Adapter__c,skuid__Model_Service_Credential__c,skuid__Model_Service__c,skuid__Page_Assignment__c,skuid__Page_Interaction__c,skuid__Page_Version__c,skuid__Page__c,skuid__Personalization_Settings__c,skuid__Preferences__c,skuid__Theme__c,z_ChildRelationship__c,z_FieldDescription__c,z_MetaDumpSetting__c,z_SObjectDescription__c,z_SchemaTemp__c" enclosevalueinquotes="true" value="{{Id}}"/>
                                <default type="fieldvalue" field="SubscriberId" fieldtargetobjects="User" enclosevalueinquotes="true" value="{{$Model.CurrentUser.data.0.Id}}"/>
                            </defaults>
                        </action>
                        <action type="save">
                            <models>
                                <model>EntitySubOpp</model>
                            </models>
                        </action>
                        <action type="requeryModel" model="Opportunity" behavior="standard"/>
                        <action type="unblockUI"/>
                    </actions>
                </action>
                <action type="massupdate"/>
                <action type="massdelete"/>
            </massactions>
            <views>
                <view type="standard"/>
            </views>
            <searchfields/>
        </skootable>
    </components>
    <resources>
        <labels/>
        <css/>
        <javascript>
            <jsitem location="inlinesnippet" name="renderOpportunityFeed" cachelocation="false">var field = arguments[0],
                $ = skuid.$;
                
                //initialize a string for the chatter feed
                var value = '';
                
                //get our model that has our chatter feeds for the 
                //opportunities in our table
                var UpdatesToShow = skuid.model.map().OpportunityFeed;
                //console.log(UpdatesToShow);
                
                //use jQuery for each function to loop over 
                //the opportunity feed rows.  when we find a 
                //matching opportunity we concatenate the feed
                //to the value string that we render into the 
                //model ui field
                $.each(UpdatesToShow.data, function(i, v) {
                   
                   if(v.Body !== undefined &amp;&amp; v.Body !==null &amp;&amp; v.Body !=='') {
                //   console.log ('Parent Id ' + v.ParentId);
                //   console.log ('Opportunity Id ' + field.row.Id);
                //   console.log ('Body ' + v.Body);
                   
                       if(v.ParentId == field.row.Id) {
                        //use jQuery .text() to remove HTML
                        value = value + $(v.Body).text() + '; ';
                //        console.log(value);
                       }
                   }
                    
                });
                
                //render the field in read and edit mode
                if(field.mode == 'read') {
                    
                    skuid.ui.fieldRenderers.STRING.read(field, value);
                }
                
                if(field.mode == 'edit') {
                    
                    skuid.ui.fieldRenderers.STRING.edit(field, value);
                }
            </jsitem>
        </javascript>
    </resources>
    <styles>
        <styleitem type="background" bgtype="none"/>
    </styles>
</skuidpage>