+ Start a Discussion
RSTRST 

How to get User not having access Error on New button click on Account.?

Hi,

 

I have a "New Account" button on Account object.

this new Account button redirects to another visualforce page.

 

Now, i want When a user clicks the "New Account" button on the Account Page Layout and they do not have the "Create" permission on their user profile or granted through permission sets, the following error message is displayed: "You have insufficient privileges to create Accounts".

T-HanT-Han

As per my understanding you would like to Restrict the profile person to create a new account? 

If thats the case you can imply Sharing settings to the particular Roles.

 

Let me know if that is not the case you are looking for..

Venkat PolisettiVenkat Polisetti

Do that check in your Visualforce page and Custom controller or Controller Extension.

 

NOTE: Untested code below.

 

  1. On your visualforce page, put a page action an wire it up call the controller method. 

                  <apex:page controller="AcountCustomController" action="{!checkAccess}" >

                             <apex:outputpanel rendered="{!NOT(hasCreateAccess)}">

                                     YOU DO NOT HAVE CREATE ACCESS TO ACCOUNTS

                              </apex:outputpanel>

                   </apex:page>

 

 2. In your controller:

               public class AcountCustomController {

                       public hasCreateAccess {get;set;}

                     

                      public AccountCustomController() {

                               hasCreateAccess = false;

                      }

 

                       public Pagereference checkAccess() {

                                  if (Schema.SobjectType.Account.isCreateable())

                                              hasCreateAccess = true;

                       }

               }

 

I guess, you get the point here. Let me know how it goes.

 

Thanks,