2

I stumbled upon this issue in Lightning where a user was not able to see a record in a Lightning component, even though the Apex controller Class didn't have any with sharing or without sharing defined.

For other lightning components with similar structure, it seems to works fine and the record are displaying as it is running in system context.

2

The only difference was, the VF page from which this component was called had the Account object as standard controller, so I believe even though there was no extension defined when I called the Lightning component it took the the lightning component's controller as an extension to the VF page. So it ran the SOQL in the apex controller method in user context.

After I made the Controller without sharing it worked just fine. Thought this might be helpful to others as well. Do let me know if my understanding is incorrect.

1

There are very few occasions when you should really use without sharing. Below is what the documentation states:

Use the without sharing keywords when declaring a class to ensure that the sharing rules for the current user are not enforced. For example, you may want to explicitly turn off sharing rule enforcement when a class acquires sharing rules when it is called from another class that is declared using with sharing.

Its one of the best practice to use with sharing. What you mentioned tells me that you are accessing a record which you may really not have access to.

Please double check your org's sharing settings and profile configuration to ensure that this will not allow you any access to records which you shouldnt see. Depending on the number of users/ different kinds of users using the system this has the potential to result in breach of information.

I would in this case ideally find out the root cause on why i am not able to see this record.What you have done according to me is a work around :)

All classes should have the with sharing keyword when we create it.

0

You can access records without using Apex class in Lightning component by Lightning Data Service, but it's available as a Beta. Salesforce not release this service till now. Check out this documentation

(https://developer.salesforce.com/docs/atlas.en-us.lightning.meta/lightning/data_service.htm)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.