Skip to main content

Connect #ZOOM with #Salesforce using #Zapier | Salesforce Tutorials

Custom Aura Feed Component | forceChatter:feed | Chatter in Salesforce




Hello guys, 

In this article I will create a custom aura feed component with two picklists to select Group and then based on the Group selection, select user inside that Group and display the chatter of that particular user.

Please follow the code below : 

FeedComponent.cmp
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<aura:component controller="feedComponentCTRL" implements="force:appHostable">
    <aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute name="options" type="List" />
    <aura:attribute name="type" type="String" default="News" description="The type of feed" access="GLOBAL"/>
    <aura:attribute name="types" type="String[]"
                    default="Bookmarks,Company,DirectMessages,Feeds,Files,Filter,Groups,Home,Moderation,Mute,News,PendingReview,Record,Streams,To,Topics,UserProfile"
                    description="A list of feed types"/>
    <div class="slds-grid slds-gutters">
        <div class="slds-col">
            <p style="font-size:larger; color:black; font-weight:bold">Groups</p>
            <ui:inputSelect aura:id="Groups" class="slds-input" change="{!c.onGroupChanged}"/>
        </div>
        <div class="slds-col">
            <p style="font-size:larger; color:black; font-weight:bold">Users</p>
            <ui:inputSelect aura:id="Users" class="slds-input" change="{!c.onUserChanged}"/>
        </div>
    </div>
    <br/>
  
     <div aura:id="feedContainer" class="feed-container">
        <forceChatter:feed />
    </div>
</aura:component>


FeedComponentController.js
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
({
    // Handle component initialization
    doInit : function(component, event, helper) {
        helper.fetchPickListVal(component);
    },

  
    onGroupChanged : function(component, event, helper) {
        var groupId='';
        var value = component.find("Groups").get("v.value");
        var action = component.get("c.getGroupID");
        action.setParams({
            "groupName": value
        });
        action.setCallback(this, function(response) {
            if (response.getState() == "SUCCESS") {
                console.log('###Success');
                groupId = response.getReturnValue();
                console.log('###Group ID : '+groupId);
                //
                //
                var opts = [];
                var action1 = component.get("c.getGroupUsers");
                action1.setParams({
                    "groupId": groupId
                });
                action1.setCallback(this, function(response1) {
                    if (response1.getState() == "SUCCESS") {
                        //
                        //
                        var allValues = response1.getReturnValue();
                        if (allValues != undefined && allValues.length > 0) {
                            opts.push({
                                class: "optionClass",
                                label: "--- None ---",
                                value: ""
                            });
                        }
                        for (var i = 0; i < allValues.length; i++) {
                            opts.push({
                                class: "optionClass",
                                label: allValues[i],
                                value: allValues[i]
                            });
                        }
                        component.find("Users").set("v.options", opts);
                        //
                        //
                        //
                    }
                    else{
                        var errors = response1.getError();
                        console.log('###Error'+errors[0].message);
                    }
                });
                $A.enqueueAction(action1);
                //
                //
                //
            }
            else{
                var errors = response.getError();
                console.log('###Error'+errors[0].message);
            }
        });
        $A.enqueueAction(action);
    },
    onUserChanged : function(component, event, helper){
        var value = component.find("Users").get("v.value");
        var action = component.get("c.getUserId");
        action.setParams({
            "userName": value
        });
        action.setCallback(this, function(response) {
            if (response.getState() == "SUCCESS") {
                value = response.getReturnValue();
                //
                //
                var type = component.get("v.types");
                var types = component.get("v.types");
                var feedContainer = component.find("feedContainer");
                var feedContainers=[];
                //  for(var i=0; i<component.get("v.userIds").length; i++){
                for (var j = 0; j < types.length; j++) {
                    // console.log('!!!'+component.get("v.userIds["+i+"]")+'-'+types[j]);
                    $A.createComponent("forceChatter:feed", {"type": types[j], "subjectId": value}, function(feed) {
                        feedContainers.push(feed);
                    });
                }
                //}
                feedContainer.set("v.body", feedContainers);
                //
                //
            }
            else{
                var errors = response.getError();
                console.log('###Error'+errors[0].message);
            }
        });
        $A.enqueueAction(action);
    }
})


FeedComponentHelper.js
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
({
	fetchPickListVal: function(component, elementId, plType) {
        var action = component.get("c.getGroups");
        var opts = [];
        action.setCallback(this, function(response) {
            if (response.getState() == "SUCCESS") {
                var allValues = response.getReturnValue();
                if (allValues != undefined && allValues.length > 0) {
                    opts.push({
                        class: "optionClass",
                        label: "--- None ---",
                        value: ""
                    });
                }
                for (var i = 0; i < allValues.length; i++) {
                    opts.push({
                        class: "optionClass",
                        label: allValues[i],
                        value: allValues[i]
                    });
                }
                component.find("Groups").set("v.options", opts);
            }
            else{
                var errors = response.getError();
                console.log('###Error'+errors[0].message);
            }
        });
        $A.enqueueAction(action);
    }
})


feedComponentCTRL.apxc
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
public class feedComponentCTRL {
    @AuraEnabled
    public static List < String > getGroups() {
        String userId=UserInfo.getUserId();
        List<String> grpList = new List<String>();
        List<CollaborationGroup> grp = [select name from CollaborationGroup where CreatedById=:userId];
        for(CollaborationGroup s:grp){
            grpList.add(s.name);
        }
        return grpList;
    }
    @AuraEnabled
    public static String getGroupID(String groupName) {
        List<CollaborationGroup> grp = [select Id from CollaborationGroup where Name=:groupName limit 1];
        return grp[0].Id;
    }
    @AuraEnabled
    public static String getUserId(String userName) {
        List<User> u = [select Id from User where Name=:userName limit 1];
        return u[0].Id;
    }  
    @AuraEnabled
    public static List<String> getGroupUsers(String groupId) {
        List<String> usersIdsInGroup= new List<String>();
        List<CollaborationGroupMember> groupMembers=[Select Id, memberid, Member.Name, CollaborationGroupId From CollaborationGroupMember where CollaborationGroupId=:groupId];
        system.debug('### groupMembers size: '+groupMembers.size());
        for(CollaborationGroupMember gm : groupMembers)
        {
            usersIdsInGroup.add(gm.Member.Name);
        }
        return usersIdsInGroup;
    }
}

Output

Salesforce Bolt

Comments

Post a Comment

Popular posts from this blog

How to send WhatsApp from Lightning Component Salesforce ?

Send WhatsApp from Lightning Component SalesforceHi folks, in this article I will explain how you can send WhatsApp from Lightning Component using https://wa.me/
In this example I will create a Quick Action button on Contact which will be connected with my Lightning Component.
Please follow the steps below : 
Step 1 : Create a Lightning Component & Apex as shown below
WhatsApp.cmp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30<aura:componentcontroller="Vlog_whatsappCTRL"implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"access="global"><aura:attributename="recordId"type="String"/><aura:attributename="con"type="Contact"/><aura:attributename="msg"type="String"/><aura:handlername="init"action…

Send WhatsApp and Save Chat using Lightning Component Salesforce | Salesforce Tutorials

Hello folks,
In this article you will learn to send WhatsApp and Save the Chat using Lightning Component Salesforce. 
Prerequisite : 
Create a custom object WhatsApp__c
Create custom fields as shown below : 


Please follow the code below : 

WhatsAppComponent 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30<aura:componentcontroller="Vlog_whatsappCTRL"implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction"access="global"><aura:attributename="recordId"type="String"/><aura:attributename="con"type="Contact"/><aura:attributename="msg"type="String"/><aura:handlername="init"action="{!c.doInit}"value="{!this}"/><articleclass="slds-card"><divclass="slds-card__header…

Get Parent Id when overriding standard actions with a Lightning Component in salesforce1 app

How to Get Parent Id when overriding standard actions with a Lightning Component in salesforce1 app ?
In this blog I will explain how you can get Parent Id when overriding standard actions with a lightning component.
For example I have changed my Opportunity New button action with a custom Lightning Component. 
Let's create a new account and from the related tab try creating the new Opportunity. Have you noticed any change in URL ?
Let me share the URL with you :  _________________________________________________________________________ https://kapilbatra1-dev-ed.lightning.force.com/lightning/o/Opportunity/new?recordTypeId=0127F000000htlpQAA&additionalParams=accid%3D0017F00002S6g9H%26&inContextOfRef=1.eyJ0eXBlIjoic3RhbmRhcmRfX3JlY29yZFBhZ2UiLCJhdHRyaWJ1dGVzIjp7Im9iamVjdEFwaU5hbWUiOiJBY2NvdW50IiwicmVjb3JkSWQiOiIwMDE3RjAwMDAyUzZnOUhRQVIiLCJhY3Rpb25OYW1lIjoidmlldyJ9LCJzdGF0ZSI6e319&count=3 _________________________________________________________________________
In above URL you …