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
arunadeveloperarunadeveloper 

Display "{faultcode:'sf:INSUFFICIENT_ACCESS',FAULTSTRING:.} user friendly

Hi there,

 

I am having a custom button.

when i click on that custom button it call a visual force page. This visual force (apex class) page is assigned to some profile only.

we do have other profiles which are not having access to this visual force(apex class) page. so when i click on the custom button i am getting insufficient access message which is ok.

But my question is can we display  "{faultcode:'sf:INSUFFICIENT_ACCESS',FAULTSTRING:'APEX CLASS name;no access allowed to this class.}" this message user-friendly like "you don't have access to this button ".

 

or can we have any security for custom button , like display button only those profile which are having access to the page and class.

 

thanks

inadvance

ericmonteericmonte

If you want a friendly error message, I suggest you make that button available to all profiles then in your Visualforce page, you can check to see if the running user is part of a profile that hass access to this page or not.

 

 

If the user's profile should not have access to this page then throw error message and display it your apex page message.

arunadeveloperarunadeveloper

Hi Thank you for replay,

 

How to check in visualforce page running user.

i think you mean in apex class right, if it is vf page can you please suggest me how to do that.

 

Thanks

Inadvance

ericmonteericmonte

There are few ways you can do it.

Scenario 1:

1. If it's simple VF page that has pageBlocks, you can use the rendering component of the pageblock and use a global variable to check for the profile. So for example, I would create a Page Block with some text and Say "Your profile doesn't have access to this page, please see your adminstrator..." and only render this for certain profiles.

2. You do the opposite of one, where you have a pageBlock to be rendered only for those who should have access.

here is a link to global variables.

http://www.salesforce.com/us/developer/docs/pages/Content/pages_variables_global.htm

 

Scenario 2:


You can also do a custom button on the page that uses a Javacscript to check for the user profile. If user profile should not have access to this then throw error message in the Javascript. And if the user should have access to this page then they can be redirected to the VF page.

 

Scenario 3:


1. When the controller loads in the VF Page, you can retrieve the user's profile and if this profile should not have permission then throw the error message in apex page message. You can even put this a try catch method.

 

Scenario 4:

If you do not want to do anymore customization then use the Out of the Box feature and create a different page layout for uses who should have access to this button. Since your VF page is tied to a specific profile, you can set different page layout for those profile who should have access to the button or not. This would be a cleaner approach but now you will have more than one page layout. :)

 

 

There are other ways you can handle this as well by creating custom error message and so forth, but in the end how much customization are you willing to do and how much time do you want to spend on this.