3

we recently decided to refactor coding which uses hardcoded Ids and Names for permission checks on profiles. We want to use custom permissions, which then can be added to permission sets and therefore make it easier to fine tune the permission scheme. And it's pretty easy to use in Visualforce and APEX as well.

However we kind of ran into a road block with javascript coding stored in static resources. We cannot use the $Permission.[Permissionname] here, like we could in javascript of visualforce pages. At least we guess so, because it's not working. :-)

Is there a way to access custom permissions of the user from within Javascript Coding which is stored in static resources?

I am aware, that there are ways to get some system information like:

var userInfo = sforce.connection.getUserInfo();

Is there a similar thing to get the custom permissions?

1 Answer 1

3

Typically, I would just namespace it in from the page using the resource. You could do something like:

<apex:page>
    <script>
        (function (w) {
            "use strict";
            w.Permissions = w.Permissions || {};
            w.Permissions.PermissionName = $Permission.PermissionName;
            // and so on
            Object.freeze(w.Permissions);
        })(window);
    </script>
    <apex:includeScript ... />
</apex:page>

You only have to merge in those permissions you care about for the specific interface. Then, in your resource, you can make the same check if this object is defined (that first line after "use strict"), and use the merged values to your heart's content.

//in resource
(function (w) {
    "use strict";
    permissions = w.Permissions || {};
    if (permissions.MyPermission) {
        // do stuff
    }
})(window);
1
  • Thanks for your quick answer Adrian. The problem we run into is that the calling page is part of a managed package, we don't have the edit rights for. The developers of the package added this "backdoor" to allow us customization of their pages via the static resource.
    – mseehase
    Apr 6, 2018 at 7:23

You must log in to answer this question.

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