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
sfadm sfdevsfadm sfdev 

How to change the permissions of the currently logged user by using javascript code?

Hello,

I have created a custom javascript button and I've implemented my own javascript code to unlock the Opportunity record when the record is submitted for approval.
When I remove the "Modify All" permissions from the Opportunity Permission Set for particular user and the custom unlock button is clicked, an error message appears that the currently logged user does not have permissions to unlock the Opportunity object.
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. For more information, see Insufficient Privileges Errors.
What I need to know is:
1. How to get the ID of the currently logged user via javascript?
2. How to modify and alter the permission set of the currently logged user via javascript?
- in the currently logged user I must set "Modify All" permissions via javascript when the current user does not have such permissions?

Thank you
JLA.ovhJLA.ovh
Instead of running Javascript behind your custom button, you could run a Visualforce page. The action of that page can be in a class with system privileges, this will override the standard capability of your user with the proper Apex code.
It will be more secure too, avoiding "privilege extensions" hacks. And this will spare API calls too
sfadm sfdevsfadm sfdev
Hi,

Could you please advise how this can be achieved?

Instead of setting "Modify All" permissions via javascript to the currently logged user what I want to achieve is:
Give back the "Modify All" permissions to the user hence allowing the user to unlock the Opportunity object but I need to make certain fields to remain locked.

Please advise how this can be achieved.

Have to mention that some of the fileds which are necessary to remain unlocked are required fields.

Thank you