1

Only user with Manage Account permission set can use this button, I have created this button but how can I add permission set with error message for other user. Could Anyone help me about this . Thanks in advance

{!requireScript("/soap/ajax/32.0/connection.js")} 

var add = new sforce.SObject("Address"); 

add.Id = "{!Address.Id}"; 

add.Integration= true; 

sforce.connection.update([add]); 

window.location.reload(); 



var result = sforce.connection.query( SELECT PermissionSetId, PermissionSet.Name FROM PermissionSetAssignment WHERE 
PermissionSet.Name = 'Manage PS Accounts']); 

var psAssignment = result.getArray("records"); 
if(psAssignment.length === 0) 
{ 
alert('You don't have access to this functionality.'); 
}
  • whats the issue you are facing? – Santanu Boral Apr 6 '17 at 21:20
  • You need to write the redirection and update inside else part – Raul Apr 6 '17 at 21:21
6

There's no need to go through all this work. Just create a custom permission, then access it via $Permission:

if({!$Permission.Manage_Accounts}) {
    var record = new sforce.SObject("Address");
    record.Id = "{!Address.Id}";
    record.Integration = true;
    var results = sforce.connection.update([record]);
    // Consider checking results to ensure success or show error
    if(!results[0].getBoolean("success")) {
        alert("Error: "+results[0].errors[0].message);
    }
    window.location.reload();
} else {
    alert("You don't have access to this feature.");
}

I suspect that your object name and fields may not be correct; if they are custom, make sure you include the __c.

| improve this answer | |
  • Thank you very much. It worked and learned new things today. Appreciate it. – SFlast Apr 7 '17 at 2:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.