Sometimes you may get requirement as below,
1. Create a Custom Button (JavaScript) and assign it to the page layout.
2. Create a Custom Permission Set.
3. If the logged in user not assigned in the specified permission set, then just throw an alert like "You don't have sufficient Permission". Else navigate to another page or whatever based on your requirement.
Custom Button JavaScript Code:
- {!REQUIRESCRIPT("/soap/ajax/32.0/connection.js")}
- var result = sforce.connection.query("SELECT Id FROM PermissionSetAssignment WHERE PermissionSet.Name = 'Payment_Type_Permission_Set' AND AssigneeId = '{!$User.Id}'");
- var psAssignment = result.getArray("records");
- if(psAssignment.length === 1){
- window.location.href = '/apex/PaymentChange?id={!Log__c.Id}';
- }
- else
- {
- alert('You do not have sufficient permission. Please contact your administrator.');
- }
1. Initialized the REQUIRESCRIPT resource for SOQL query.
2. Queried PermissionSet using sforce.connection.query.
Where,
PermissionSet.Name is API name of the Permission Set.
AssigneeId use
3. In apex we will check the List size, here get records using getArray method and assign it to var.
4. Check variable length which is equal to list size.
5. Finally, do logic as need.
References: