+ Start a Discussion
Jeremiah CochranJeremiah Cochran 

Prevent custom lightning component related list from rendering if the user does not have access to the object

Hi and thank you in advance.

I have a lighting component that serves as a custom related list for a custom object, we'll call testObject__c. The lighting component lives on a standard object, Opportuniy. Here is what i am trying to prevent: when a user that has access to the Opporuntity object views an Opportunity record, but they don't have access to the custom object (testObject__c) they get an error on their screen which I have determined is because the Lighting Component related list for the custom object (testObject__c) is still trying to load.

I have added an attribute which gets set based on this:

Boolean userCATMAccess = Schema.sObjectType.testObject__c.isAccessible();

However, even though that check comes back false the Lighting Component related list still tries to render and throws the error.

My question is how do I prevent the Lighting Component related list from trying to render if the user does not have access to the testObject__c but does have access to Opportunity records?

Alain CabonAlain Cabon

It is an interesting question.

You cannot prevent totally the call to the Lightning component itself but you can close the popup of the quick action (init event) (if it is one here) immediatly as soon as you have got false from the test on Boolean userCATMAccess which works.
It is more a workaround.

Did you use with sharing for your controller?
	doInit : function(component, event, helper) {
        // your test of Boolean userCATMAccess 
        if (!userCATMAccess) {
            }, 100);

Jeremiah CochranJeremiah Cochran
Hi Alain, the workaround provided didn't work, the error still shows.
Alain CabonAlain Cabon
Hi Jeremiah,  

No one helps you here because you don't provide any code (nothing).  The problem could be an other reason.No code, no help most of the time.
Just one wrong word in your code, all will fail.  

Show us your code and we will fix it immediatly probably.