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.'); 
}
2
  • whats the issue you are facing? Commented Apr 6, 2017 at 21:20
  • You need to write the redirection and update inside else part
    – Raul
    Commented Apr 6, 2017 at 21:21

1 Answer 1

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.

1
  • Thank you very much. It worked and learned new things today. Appreciate it.
    – SFlast
    Commented Apr 7, 2017 at 2:25

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .