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
RSTRST 

How to get the error on clicking on new button on account if user doesnt hv permission of creating.?

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".

SurekaSureka

Try using "With Sharing" in the controller of corresponding VF page.

 

Thanks

Rajesh SriramuluRajesh Sriramulu

Hi,

 

Since when user click 'New Button' it will navigate to VF page right.

 

Then u can do 2 ways.

1.In profile goto down and find out 'Enabled Apex Classes Access' remove the controller or extension of that VF page in that.

2. create one custom button on Account and do some validation onit and if it ok then navigate to that VF page.

 

Regards,
Rajesh.

RSTRST

thanks for your reply!!!

but i need to check the create permission of user as soon as i click the "NEW ACCOUNT" button and throw an error if he doesn't hv access to the account creation....may b we need to write a class and then call that class on click of button.

** NEW ACCOUNT is a custom button.

Rajesh SriramuluRajesh Sriramulu

Hi,

 

When u click on that button u just override to VF page.

 

And try it as with 1 option it will throw an error insufficient priviligers.

 

Regards,

Rajesh.

RSTRST
but there are lots of profiles ....so will it be a good solution to go in each profile and do the changes....coz in some of the cases we have given permission through PERMISSION SET.
Rajesh SriramuluRajesh Sriramulu

HI,


Then go like this,

 

if (Schema.sObjectType.Contact.fields.Email.isCreateable()) {
   // Create new contact
}

 

Regards,

Rajesh.

RSTRST
should i write a class or where can i use this?
Rajesh SriramuluRajesh Sriramulu

Hi,

 

Not sure. Try to write in custom button and validate it. else as u told try for  class.

 

Regards,

Rajesh.