Hello friends, In this post you will see an example that helps you to understand, how to use custom setting in lightning web component(lwc).

Custom setting in lightning web component

By using custom setting you can access cached data stored on salesforce platform in lighting web component. Let's see an example.

CustomSettingHandler.apxc

 public class CustomSettingHandler {

@AuraEnabled(cacheable=true)
public static DemoCustomSetting__c getCustomSettings(){
return DemoCustomSetting__c.getOrgDefaults();
}
}
CustomSetting.html
 <template>
<lightning-card variant="Narrow" title="Custom Setting in LWC" icon-name="standard:account">
<div class="slds-align_absolute-center">
<span>Name : <b>{myCustomSettings.data.Name__c}</b></span>
</div>
</lightning-card>
</template>
CustomeSetting.js
 import { LightningElement, wire } from 'lwc';
import getCustomSettings from '@salesforce/apex/CustomSettingHandler.getCustomSettings';
export default class CustomSetting extends LightningElement {
@wire(getCustomSettings) myCustomSettings;
doSomething() {
let a = this.myCustomSettings.data.Name__c;
// do something...
}
}
CustomSetting.js-meta.xml
 <?xml version="1.0"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>51.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordAction</target>
</targets>
</LightningComponentBundle>

Output:


Hope you like this post, for any feedback or suggestions please feel free to comment. I would appreciate your feedback and suggestions.
Thank you.