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
Tom H.Tom H. 

Organization.id and necessary CRUD Access for user profiles

Are there profile settings that can make the "Organization" object available to non-admin users?

 

My application runs fine for admins but blows-up for non-admin users in the following method:

 

    public static id getOrgId() {
        return [Select o.Id From Organization o limit 1].get(0).id;
    }

 

The error shown on the page is:

Insufficient Privileges
You do not have the level of access necessary to perform the operation you requested. Please contact the owner of the record or your administrator if access is necessary.

 

Please advise.

Tom

Best Answer chosen by Admin (Salesforce Developers) 
Tom H.Tom H.

You are right.  Unfortunately, setting "view all data" on for every user (in effect, making every user a sys admin) would create some security concerns.  The good news is that I did find a solution so I'm posting it here so others will benefit....

 

      System.UserInfo.getOrganizationId()

 

While I thought it was odd that a method called  "getOrganizationId()" is available on a class called "UserInfo", I'm not going to complain.  It solved my problem.  This code appears to run without failing for both non-system admin and system admin users.

All Answers

forecast_is_cloudyforecast_is_cloudy

The respective user profile has to have "View All Data" privilege (which the System Admin Profile has) in order to access the Organization object.

Tom H.Tom H.

You are right.  Unfortunately, setting "view all data" on for every user (in effect, making every user a sys admin) would create some security concerns.  The good news is that I did find a solution so I'm posting it here so others will benefit....

 

      System.UserInfo.getOrganizationId()

 

While I thought it was odd that a method called  "getOrganizationId()" is available on a class called "UserInfo", I'm not going to complain.  It solved my problem.  This code appears to run without failing for both non-system admin and system admin users.

This was selected as the best answer
forecast_is_cloudyforecast_is_cloudy

Perfect. That code would work for all Users. I didn't realize that all you wanted was the Id of the Organization. I had thought that you wanted to query additional Org related information. Thanks for posting your solution for the benefit of the rest of the community....