Thursday, June 28, 2018

Dynamically Show The List View Based on Selected Object Name and Show Object Records Based On List View Selection

HI Guys, in this Post I am showing how to Show List View Dynamically based on Object Name and Showing The Data Based On Selected List View Name.


Monday, June 25, 2018

How To Display Records Data Based On Enter Value Using Lightning Component and SOSL Query(Account, Contact, Opportunity)

In This Example, we Used Account, Contact, Opportunity and filter the Data based on Account Name, we display the contact, Opportunity Data based Account Name.



Apex Class
public class AdvancedLtngWrks {  
   @AuraEnabled  
   Public static WraperForStorage getSearchRelated(String searchName){  
     WraperForStorage wrperObj = new WraperForStorage();  
     if(searchName != null && searchName != ' ') {       
       // builiding the SOSL Query  
       String searchQuery = 'FIND \'' + searchName + '\' RETURNING Account(Id,Name,Type), Contact(Id,Name,Account.Name where Account.Name =:searchName),Opportunity(Id,Name,Account.Name where Account.Name =:searchName)';  
       list<list<Sobject>> totalResults = search.query(searchQuery);  
       Account[] accList = (Account[])totalResults[0];  
       Contact[] conList = (Contact[])totalResults[1];  
       Opportunity[] oppList = (Opportunity[])totalResults[2];  
       wrperObj.acntsLst = accList;  
       wrperObj.cntsLst = conList;  
       wrperObj.OpportunitysLst = oppList;        
     }   
     return wrperObj;   
   }  
   Public class WraperForStorage{  
     @AuraEnabled Public List<Account> acntsLst {get;set;}  
     @AuraEnabled Public List<Contact> cntsLst {get;set;}  
     @AuraEnabled Public List<Opportunity> OpportunitysLst {get;set;}  
     Public WraperForStorage(){}    
   }    
 }
Lightning Component
<aura:component controller="AdvancedLtngWrks" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId,forceCommunity:availableForAllPageTypes,force:lightningQuickAction" access="global" >
    <aura:attribute name="searchName"  type="String" />
    <aura:attribute name="acntsList" type="Account[]" />
    <aura:attribute name="contsList" type="Contact[]" />
    <aura:attribute name="OpportunityList" type="Opportunity[]" />
    <aura:attribute name="wrapperList" type="object"/>
    <div class="slds-theme_default" >
        <div class="slds-card slds-p-around--large">
            <lightning:input type="search" label="Please Enter Account Name" name="search"  value="{!v.searchName}" required="true" placeholder="SearchInAll" onkeyup="{!c.searchResult}"/>
        </div>
        <aura:if isTrue="{!v.wrapperList.acntsLst.length > 0}">
            <div class="slds-card">
                <div class="slds-text-heading_medium">
                    <strong>Search Result Based On Acount Name</strong>
                </div>
                <lightning:accordion >
                    <lightning:accordionSection name="Accounts" label="Accounts">
                        <aura:set attribute="body">
                            <table class="slds-table slds-table--bordered slds-table--cell-buffer">
                                <thead>
                                    <tr class="slds-text-title--caps">
                                        <th scope="col">
                                            <div class="slds-truncate" title="Id">Id</div>
                                        </th>
                                        <th scope="col">
                                            <div class="slds-truncate" title="Name">Name</div>
                                        </th>
                                        <th scope="col">
                                            <div class="slds-truncate" title="Type">Type</div>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <aura:iteration items="{!v.wrapperList.acntsLst}" var="con">
                                        <tr>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Id}">{#con.Id}</div>
                                            </th>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Name}">{#con.Name}</div>
                                            </th>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Type}">{#con.Type}</div>
                                            </th>
                                        </tr>
                                    </aura:iteration>
                                </tbody>
                            </table>
                        </aura:set>
                    </lightning:accordionSection>
                    <!-- second section -->
                    <lightning:accordionSection name="Contacts" label="Contacts">
                        <aura:set attribute="body">
                            <table class="slds-table slds-table--bordered slds-table--cell-buffer">
                                <thead>
                                    <tr class="slds-text-title--caps">
                                        <th scope="col">
                                            <div class="slds-truncate" title="Id">Id</div>
                                        </th>
                                        <th scope="col">
                                            <div class="slds-truncate" title="Name">Name</div>
                                        </th>
                                        <th scope="col">
                                            <div class="slds-truncate" title="AccountName">AccountName</div>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <aura:iteration items="{!v.wrapperList.cntsLst}" var="con">
                                        <tr>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Id}">{#con.Id}</div>
                                            </th>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Name}">{#con.Name}</div>
                                            </th>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Account.Name}">{#con.Account.Name}</div>
                                            </th>
                                        </tr>
                                    </aura:iteration>
                                </tbody>
                            </table>
                        </aura:set>
                    </lightning:accordionSection>
                    <!-- 3rd section -->
                    <lightning:accordionSection name="Opportunitys" label="Opportunitys">
                        <aura:set attribute="body">
                            <table class="slds-table slds-table--bordered slds-table--cell-buffer">
                                <thead>
                                    <tr class="slds-text-title--caps">
                                        <th scope="col">
                                            <div class="slds-truncate" title="Id">Id</div>
                                        </th>
                                        <th scope="col">
                                            <div class="slds-truncate" title="Name">Name</div>
                                        </th>
                                        <th scope="col">
                                            <div class="slds-truncate" title="AccountName">AccountName</div>
                                        </th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <aura:iteration items="{!v.wrapperList.OpportunitysLst}" var="con">
                                        <tr>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Id}">{#con.Id}</div>
                                            </th>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Name}">{#con.Name}</div>
                                            </th>
                                            <th scope="row">
                                                <div class="slds-truncate" title="{#con.Account.Name}">{#con.Account.Name}</div>
                                            </th>
                                        </tr>
                                    </aura:iteration>
                                </tbody>
                            </table>
                        </aura:set>
                    </lightning:accordionSection>
                </lightning:accordion>
            </div>
        </aura:if>
    </div>
</aura:component>
JavaScript Controller
({
    searchResult: function(component, event, helper) {
        var action = component.get("c.getSearchRelated");
        action.setParams({
            "searchName": component.get("v.searchName")
        });
        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                var res = response.getReturnValue();
                component.set("v.wrapperList", res);
            }
        });
        $A.enqueueAction(action);
    }
})
Please Let Us Know If You have any Queries.

Happy Learning!!!!

Tuesday, June 19, 2018

How To Check Active Users in Role, Public Group and Queue Using SOQL query.

if you want to Find Number Of Active Users In a Role use the Below simple SOQL query.

Active Users in Role:
SELECT Id, Name, Email, isActive, Profile.Name, UserRole.Name, UserType FROM User WHERE UserRole.Name = '<Role Name>' AND isActive = true 
OR 
SELECT Count(Id) FROM User WHERE UserRole.Name = '<Role Name>' AND isActive = true 
find below screenshot for more information.



Active Users In Public Group:
SELECT Id, Name, Email, isActive, Profile.Name, UserRole.Name, UserType FROM User WHERE Id IN (SELECT UserorGroupId FROM GroupMember WHERE Group.Name = '<group Name>') AND isActive = true 
OR
SELECT Count(Id) FROM User WHERE Id IN (SELECT UserorGroupId FROM GroupMember WHERE Group.Name = '<Group Name>') AND isActive = true

find below screenshot for more information


Active Users In Queue:
SELECT Id, Name, Email, isActive, Profile.Name, UserRole.Name, UserType FROM User WHERE Id IN (SELECT UserOrGroupId FROM GroupMember WHERE Group.Type= 'Queue' AND Group.Name = ' <queue Name>') AND isActive = true
OR
SELECT Count(Id) FROM User Where Id IN (SELECT UserOrGroupId FROM GroupMember Where Group.Type= 'Queue' AND Group.Name = '<queue Name>') AND isActive = true

find below screenshot for more information



How To Check Active Users In a Profile Using SOQL Query

if you want to find Active users in a profile using the Below simple query, it fetches the active users in a profile.

Query:
SELECT count() FROM User WHERE IsActive = true AND Profile.Name = '<profile_Name>' 

It shows the result in the form of Count.
Please Check the Screen Shot For More Information.


please let us know if you have any queries.
Happy Learning!!

How To Check Active Users in a Permission Set Using SOQL Query

If you want find How many Active Users in a Permission Set using SOQL query
use the Below simple query it fetches active users in Permission Set.
Query:
SELECT Count(AssigneeId) FROM PermissionSetAssignment WHERE Assignee.isActive = true AND PermissionSet.Name='<Permission set API Name>'
it gives the result in the form of Count.
Ex: if the count is Four, means 4 active users are in Permission Set.
Please Check Screen Shot for more details.

Please let us Know If you have any Queries.
Happy Learning!!