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
LukashPLukashP 

Without Sharing and ApexPages.standardController.getRecord()

Hi all,

I have pretty complicated requirements when it comes to sharing. It forced me to use apply without sharing keyword into a controller extension.

Everything would be fine, but we also use this construction in my controller extension constructor (field names are only examples :):

 

public CC_CaseExtension(ApexPages.StandardController controller) {

    if (!System.Test.isRunningTest()){
        controller.addFields(new List<String> {'field1__c,'field2__c'});
     }
     record = (Case)controller.getRecord();

}

 

Now, my CC_CaseExtension is running WITHOUT SHARING. Nonetheless, this code fails on  record = (Case)controller.getRecord(); with error "Data not available".

I debugged this and It seems that this getRecord() is called on standard controller, and I guess it tries to enforce sharing.

 

I don't know what to do. I would very much prefer not to write SOQL queries to get the record variable, as the page and the class are really complicated and actually replacing the addFields() with a SOQL query is not that easy, they work a bit differently.

 

I would be grateful for any help.

 

Regards,

Lukasz

sfdcfoxsfdcfox

You can do this:

controller.addFields( new list<string>( case.sobjecttype.getdescribe().fields.getmap().keyset() ) );

This simplifies your addFields call by simply selecting all fields.

 

In regards to the other issue, I'm fairly sure standard controllers always enforce sharing regardless of the modifier. With Sharing only affects SOQL calls. Are you sure the user should have access to the case?