function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Ty WhitfieldTy Whitfield 

My Lightning Component shows different information to different users

I've tested my Lightning Component and it worked as expected and see Contacts for displayed in my component.  Another user looking at the same account sees "There are no Team Lead or Support contacts"
public  class accController {
    @AuraEnabled
    public static list<Contact> getTrainingSubscription(Id recordId)
    {
        List<Contact> Conlist = [Select Id, Training_Subscription_User__c, Name, Email, Contact_Status__c, Last_Training_Login_Date__c from Contact where AccountId= :recordId and Training_Subscription_User__c = true ORDER By Contact_Status__c];
        return Conlist;
    }

    @AuraEnabled
    public static list<Contact> getSupportUsers(Id recordId)
    {
        List<Contact> Conlist =  [SELECT Id, Email,My_ASCI_Role__c,Name,  Experience__c FROM Contact WHERE  AccountId=:recordId AND (My_ASCI_Role__c = 'Team Lead' OR My_ASCI_Role__c = 'Support User') order by My_ASCI_Role__c desc];
        return Conlist;
    }

     @AuraEnabled
    public static decimal getAverageExperience(Id recordId)
    {      

      
        List<Contact> acctContacts = [SELECT Id, Email,My_ASCI_Role__c,Name,  Experience__c FROM Contact WHERE  AccountId=:recordId AND (My_ASCI_Role__c = 'Team Lead' OR My_ASCI_Role__c = 'Support User') order by My_ASCI_Role__c desc];
              integer j = 0; 
        decimal avgExperience = 0;
            while(j <  acctContacts.size())
            {
              avgExperience = avgExperience + acctContacts[j].Experience__c;
                   
                j++;
            } 
        
        if(acctContacts.size() != null && acctContacts.size() != 0)
        {
            avgExperience = (avgExperience / acctContacts.size());
        }
        return avgExperience;
    }

     @AuraEnabled
    public static Integer getSubPurchased(Id recordId)
    {    
       List<Account>  acct = [Select Id, Training_Subscription_Seats_Available__c FROM Account where Id= :recordId];  

      return   Integer.valueOf(acct[0].Training_Subscription_Seats_Available__c);
      
    }

     @AuraEnabled
    public static Integer getSubLeft(Id recordId)
    {      
        List<Account>  acct = [Select Id, Training_Subscription_Seats_Available__c FROM Account where Id= :recordId];  
        List <Contact>  acctContacts = [Select Id, Training_Subscription_User__c, Name, Email, Contact_Status__c, Last_Training_Login_Date__c from Contact where AccountId= :recordId and Training_Subscription_User__c = true ORDER By Contact_Status__c];
      
      return  Integer.valueOf(acct[0].Training_Subscription_Seats_Available__c) - acctContacts.size();
    }




     
       
}
 
<aura:component controller="accController" implements="flexipage:availableForRecordHome,force:hasRecordId" access="global" >
    <!--testComponentTrngSubSupportUsers-->
     <aura:attribute name="recordId" type="Id" access="global" />
    <aura:attribute name="ContactList" type="Contact[]" access="global" />
    <aura:attribute name="avg" type="Decimal" access="global" />
     <aura:handler name="init" value="{!this}" action="{!c.myAction}" access="global" />
     <lightning:card iconName="standard:case_wrap_up" title="Team Lead and Support User List">
     <aura:if isTrue="{!not(empty(v.ContactList))}">
         <center>Average Experience: <lightning:formattedNumber value="{!v.avg}"/> days</center>
    <table class="slds-table slds-table_cell-buffer slds-table_bordered slds-table_striped">
         <thead>
            <tr class="slds-text-title">
                <th  style="padding-left:10px;background-color: #0084c4 !important;background-image: none !important; color: #ffffff !important; font-size:100% !important; margin:0 !important; border:none !important;" scope="col">
                    <div class="slds-truncate" title="Name">Name</div>
                </th>
                <th  style="background-color: #0084c4 !important;background-image: none !important; color: #ffffff !important; font-size:100% !important; margin:0 !important; border:none !important;" scope="col">
                    <div class="slds-truncate" title="Email">Email</div>
                </th>
                 <th  style="background-color: #0084c4 !important;background-image: none !important; color: #ffffff !important; font-size:100% !important; margin:0 !important; border:none !important;" scope="col">
                     <div class="slds-truncate" title="Experience">Experience</div>
                </th>
                <th  style="background-color: #0084c4 !important;background-image: none !important; color: #ffffff !important; font-size:100% !important; margin:0 !important; border:none !important;" scope="col">
                    <div class="slds-truncate" title="Role">My ASCI<br/>Role</div>
                </th>
            </tr>
        </thead>
        <tbody>
   
    <aura:iteration   items="{!v.ContactList}" var="con">
        <tr>
                    <td data-label="Name" style="padding-left:10px">
                        
                      
                         <div class="slds-truncate" title="">
                             <lightning:formattedUrl  value="{! '/' + con.Id}" label="{!con.Name}"  target="_blank" />
                             </div>
                    </td>
                    <td data-label="Email">
                        <div class="slds-truncate" title="">
                             <lightning:formattedUrl  value="{! '/' + con.Id}" label="{!con.Email}"  target="_blank" /></div>
                    </td>
             <td data-label="Experience">
                        <div class="slds-truncate" title=""><lightning:formattedNumber value="{!con.Experience__c}"/> days</div>
                    </td>
                    <td data-label="Role">
                        <div class="slds-truncate" title="">{!con.My_ASCI_Role__c}</div>
                    </td>
                </tr>
        
       
    </aura:iteration>
        </tbody>
         </table>
	  <aura:set attribute="else">
                <div Style="text-align : center">  There are no Team Lead or Support contacts </div>
            </aura:set>
        </aura:if>
    </lightning:card>
	
</aura:component>
 
({
 myAction : function(component, event, helper) 
    {
        var ConList = component.get("c.getSupportUsers");
        ConList.setParams
        ({
            recordId: component.get("v.recordId")
        });
        
        ConList.setCallback(this, function(data) 
                           {
                               component.set("v.ContactList", data.getReturnValue());
                           });
        $A.enqueueAction(ConList);
        
        
        var avg = component.get("c.getAverageExperience");
        avg.setParams
        ({
            recordId: component.get("v.recordId")
        });
        
        avg.setCallback(this, function(data) 
                           {
                               component.set("v.avg", data.getReturnValue());
                           });
        $A.enqueueAction(avg);
        
        
 }
})
Best Answer chosen by Ty Whitfield
Ty WhitfieldTy Whitfield

Ahh.   Found the issue.  I didn't grant Apex Class permissions for the accController class on the profile page.  So even though the profile had all access to the Contact, Lead and Opportunity objects,  I had to go to the "Enabled Apex Class Access" section on the profile page and add accController.  That did it.  

This explains why I wasn't getting an error but my list was coming back empty. It was because the accController is what populated the Lightning Component and so without access, it wouldn't perform the query and therefore empty.

All Answers

ShirishaShirisha (Salesforce Developers) 
Hi,

Greetings!

Can you please confirm you both have the same profile and permission sets assigned as the issue could be related to the access level on the Objects for different users.

If you both did not have the same profiles then I would suggest you to check the access level on the Leads and Contacts for the affected user's profile.

Kindly mark it as best answer if it helps so that it can help others in the future.

Warm Regards,
Shirisha Pathuri

 
ANUTEJANUTEJ (Salesforce Developers) 
Hi Ty,

Can you try checking if all the permissions are same and if any other user with same permissions as yours are able to see the different number of contacts.

Regards,
Anutej.
Ty WhitfieldTy Whitfield
Yes, this individuals profile has modify all on Leads, Contacts and Accounts  .  
Ty WhitfieldTy Whitfield

Ahh.   Found the issue.  I didn't grant Apex Class permissions for the accController class on the profile page.  So even though the profile had all access to the Contact, Lead and Opportunity objects,  I had to go to the "Enabled Apex Class Access" section on the profile page and add accController.  That did it.  

This explains why I wasn't getting an error but my list was coming back empty. It was because the accController is what populated the Lightning Component and so without access, it wouldn't perform the query and therefore empty.

This was selected as the best answer