+ Start a Discussion
jaw999jaw999 

Team and Other Criteria defined access to VF Page - UserRecordAccess



I have a private feature VF page on an Account. Our Account sharing model is Public Read with Edit rights given via Account Teams.

I want to display this VF page only to:

- Account Team Members
- 'Global Access People' defined on their User record
- Anyone else with Edit access, using UserRecordAccess

My latest attemp fails, does not return true for me as someone who has Edit access- 

public class AccountUserRecordAccessChecker2{

   public ApexPages.StandardController sc;
    public AccountUserRecordAccessChecker2(ApexPages.StandardController sc) {
        this.sc = sc;
    }

    
public boolean renderELEMENT(){
    if ([select count() from User
            where Id = :UserInfo.getUserId() and Admin_Team__c = true] > 0) {
        return true;
    }
    if ([select count() from AccountTeamMember
            where UserId = :UserInfo.getUserId() and AccountId = :sc.getId()] > 0) {
        return true;
    }
    if([
  SELECT
    MaxAccessLevel,
    RecordId
  FROM
    UserRecordAccess
  WHERE
    UserId = :UserInfo.getUserId() AND
    RecordId = :sc.getId()
  LIMIT 1
  ].size() > 0)
{
    return true;
}
    else {
    return false;
    }
   
}

}

Right now, no queries even fire when I load the page with this:
<apex:page standardController="Account" extensions="AccountUserRecordAccessChecker2"  rendered="{AccountUserRecordAccessChecker2.renderELEMENT}" >

Also, I can't get a system.debug to compile in the class. 


AshlekhAshlekh
Hi,

I think you need to change "renderELEMENT" to "getRenderELEMENT" in class only.
jaw999jaw999
I did this. I get no queries still.
29.0 APEX_CODE,DEBUG;APEX_PROFILING,INFO;CALLOUT,INFO;DB,INFO;SYSTEM,DEBUG;VALIDATION,INFO;VISUALFORCE,INFO;WORKFLOW,INFO
15:52:54.039 (39167921)|EXECUTION_STARTED
15:52:54.039 (39221203)|CODE_UNIT_STARTED|[EXTERNAL]|066K00000009f0C|VF: /apex/RenderPage
15:52:54.052 (52552617)|CODE_UNIT_STARTED|[EXTERNAL]|01pK0000000G882|AccountUserRecordAccessChecker2 <init>
15:52:54.052 (52582385)|SYSTEM_MODE_ENTER|true
15:52:54.053 (53431527)|METHOD_ENTRY|[1]|01pK0000000G882|AccountUserRecordAccessChecker2.AccountUserRecordAccessChecker2()
15:52:54.053 (53444644)|METHOD_EXIT|[1]|AccountUserRecordAccessChecker2
15:52:54.053 (53526057)|CODE_UNIT_FINISHED|AccountUserRecordAccessChecker2 <init>
15:52:54.881 (55756577)|CUMULATIVE_LIMIT_USAGE
15:52:54.881|LIMIT_USAGE_FOR_NS|(default)|
  Number of SOQL queries: 0 out of 100
  Number of query rows: 0 out of 50000

etc
jaw999jaw999
no qeries at all?