Wednesday, March 11, 2020

How To Check Whether CheckBox Is Checked/Selected/Ticketed Or Not in LWC

If you want to check this functionality we can relay on the event object of the java script which will tells you whether check box is selected or not.

checkboxSelection.html

<template>
 <lightning-input type="checkbox" label="" onchange={selectDeselectAll}>
    </lightning-input>
</template>

checkboxSelection.js

import { LightningElement} from 'lwc';
export default class CheckBoxClassDet extends LightningElement
{
    
 selectDeselectAll(event) {
        if (event.target.checked)
  {
    console.log('Check box is checked');
  }
  else
  {
    console.log('check box is unchecked');
  }
}

Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!

Record Is Not Createable Issue In LWC

Most of the times you will receive this error when your using the base lightning components in your application.

Recently I got the same error while I'm using the <lightning-record-form > base component in one of the LWC component.My use case is just to display the record details basis on the given record id and with set of specified fields.

RecDetails.html

<template>
<lightning-record-form 
        mode="readonly" 
        columns="2" 
        object-api-name="WebSite_Details__c" 
        record-id={recId} 
        fields={objFields} >
        </lightning-record-form>
</template>

RecDetails.js

import { LightningElement,api,track,wire } from 'lwc';
import Lan_FIELD from '@salesforce/schema/WebSite_Details__c.Language__c';
import Site_FIELD from '@salesforce/schema/WebSite_Details__c.Site__c';
import Site_FIELD from '@salesforce/schema/WebSite_Details__c.Company__c';

export default class CallPopup extends NavigationMixin(LightningElement){
    @track objFields = [Site_FIELD, Site_FIELD,Lan_FIELD];
    @track recId;
 
//Wired Method Which Returns Record id
   @wire(fetchWebDet)
    wiredfetchWebDet({ error, data }) 
    {
         
        if (data) 
            {
 this.recId = data; // Dynamically assigns the record from the response
   
     }
 }
}

When I'm executing the component I was getting the same error Record Is Not Createable.
Then I started debugging the user related profile details and I figured out the user is not having an access to create a new record.

Interesting Point To Be Noted Here Is:

But still I'm not trying to create any new record,just trying to display the record which is already exist but it's internally trying to create a new record but logged in user is not having a create access on the specified object so it's failing.

If you look at the code I'm fetching the record id dynamically from wired method and assigning to it recId which is record Id in my case.So,here what is happening is the <lightning-record-form > will display the record details in view mode in case if record-id value is available if not then it will try to create a new record.

When the component got rendered this recId is not available so it's trying to create a new record that is why it's causing issue.

Solution:

Simple if condition which checks the whether record id is available would solves this problem.So,please invoke <lightning-record-form > if and only if record id is available.If record id is not available don't invoke the <lightning-record-form > .This solves the issue.Please find the update code below.

<template>
 <template if:true={recId}> //This if check solves your problem
  <lightning-record-form 
   mode="readonly" 
   columns="2" 
   object-api-name="WebSite_Details__c" 
   record-id={recId} 
   fields={objFields} >
  </lightning-record-form>
 </template>
</template>



Please comment or write us if you have any queries/requirements.

Please like,follow,bookmark,subscribe this site to receive daily updates.




Hope this helps you..Enjoy..!