0

I have a requirement to add hyperlinks to record name only for certain user with specific permission set.

html file:

  <a data-record-id={f.Id} onclick={handleClick} target="_blank">&nbsp;&nbsp;{f.Name}</a>

js file:

@wire(getList)
listresults;

handleClick (event) {

    this[NavigationMixin.Navigate]({
        type: 'standard__recordPage',
        attributes: {
            recordId: event.target.dataset.recordId,
            actionName: 'view'
        }
    });
}
5
  • Could you share a little more detail on the specific permission? Is it access set on a profile/permission set, or something else?
    – Instread
    Commented Oct 11, 2020 at 23:59
  • I want to check whether a User has a specific Permission Set assigned or not. Based on that user should be shown hyperlink . Commented Oct 12, 2020 at 0:22
  • There's no short way to check permission set assignments in LWC. You would need to query the user's permission set assignment using the wire service, and enable/disable the link in JavaScript accordingly: help.salesforce.com/…
    – Instread
    Commented Oct 12, 2020 at 0:36
  • Thanks. I am getting the result through wire services only whether that permission set is assigned or not, but how do I enable/disable the link in js/html. That is main concern. I am new to lwc. Commented Oct 12, 2020 at 0:40
  • Using a Custom Permission assigned via Permission Set is more maintainable than checking for Permission Sets by name.
    – David Reed
    Commented Oct 12, 2020 at 1:30

1 Answer 1

0

You could create a new style class in your CSS file that disables the link:

.disabledlink {
    pointer-events: none;
}

Set up a variable that's blank by default:

linkStyleClass = "";

But gets set to "disabledlink" if the user does not have the permission set assignment:

@wire(checkPermissionSetAssignment)
wiredPermissionSetAssignmentCheck({ error, data }) {
    if (data) {
        // Not sure what data you're getting back, but you could do a check here if not done in the Apex method
        this.linkStyleClass = "disabledlink";
    }
}

And finally, set that variable as the style class value in your link that will be enabled/disabled by that variable's value:

<a data-record-id={f.Id} onclick={handleClick} target="_blank" class={linkStyleClass}>&nbsp;&nbsp;{f.Name}</a>

You must log in to answer this question.

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