Skip to content
TheChatArchiveThe Chat Archive
gpt-3.5-turbo-0613· openaiHugging Face Suzhen/CodeChat

how to fetch the custom settings in lwc

  1. User

    how to fetch the custom settings in lwc

  2. Assistant

    To fetch custom settings in LWC (Lightning Web Component), you can follow these steps:

    1. Import the getOrgDefaultValues method from the @salesforce/apex module in your LWC component:
    import { LightningElement, wire } from 'lwc';
    import { getOrgDefaultValues } from '@salesforce/apex/YourApexClass.getOrgDefaultValues';
    
    1. Create a public property in your LWC component to store the fetched custom settings:
    export default class MyComponent extends LightningElement {
        customSettings;
    }
    
    1. Create a wired method in your LWC component to call the Apex method and retrieve the custom settings:
    @wire(getOrgDefaultValues)
      wiredCustomSettings({ error, data }) {
        if (data) {
          this.customSettings = data;
        } else if (error) {
          console.error('Error in fetching custom settings', error);
        }
      }
    
    1. Create an Apex class and method to return the custom settings:
    public with sharing class YourApexClass {
      @AuraEnabled(cacheable=true)
      public static CustomSettings__c getOrgDefaultValues() {
        return CustomSettings__c.getOrgDefaults();
      }
    }
    
    1. Replace CustomSettings__c with the actual name of your custom settings object.

    By following these steps, you can fetch the custom settings in LWC and store them in the customSettings property for further use.