Verify logged in User equals some OwnerId in LWC

Verify logged in User equals some OwnerId in LWC 


JS:

import { LightningElement, api, wire } from 'lwc';

import USERID from '@salesforce/user/Id';

import CASE_OWNERID from '@salesforce/schema/Case.OwnerId';

import { getRecord, getFieldValue } from 'lightning/uiRecordApi';


// Change ComponentName as per need

export default class ComponentName extends LightningElement {

    @api recordId;

    restrictCompose = false;

    userId = USERID;

    msgbody;

    @wire(getRecord, { recordId: '$recordId', fields: [CASE_OWNERID] })

    wiredRecord({error, data}){

        if (data) {

            const onwerId = getFieldValue(data, CASE_OWNERID);

            console.log('onwerId:::::::::::', onwerId, ' - userId:', this.userId);

            this.restrictCompose = onwerId == this.userId;

        } else if (error) {

            //error handling

        }

    }

}


HTML:

<template>

<div class="slds-publisher slds-publisher_comment slds-is-active">

<lightning-textarea placeholder="someMsg" label="some label" class="slds-publisher__input slds-input_bare slds-text-longform" value={msgbody}  disabled={enableCompose}>

</lightning-textarea> 

</div>

</template>

Comments