Here, we are creating an LWC (Lightning Web Components) to check whether the “Enable Opportunity Team” , “Enable OpportunitySplit” and “Multi-Currency” features are enabled. We have designed an LWC component along with a button. When the button is clicked, it invokes an Apex method to verify the enablement status of the specified objects. If any of the features are enabled, the checkbox will be checked; otherwise, it will remain unchecked.
To make a Lightning Web Component (LWC) visible to users, we set up custom settings. In these settings, there are four fields: Last_Run_Date__c
, Opportunity_Team__c
, Opportunity_Split__c
, and Multi_Currency_enabled__c
. These fields hold the latest values, making sure that the component shows the most up-to-date information
public class ConfigController {
@AuraEnabled
public static Boolean checkAndUpdateMultiCurrency() {
Boolean multiCurrencyEnabled = Schema.getGlobalDescribe().containsKey('CurrencyType');
System.debug('multiCurrencyEnabled=====>>'+multiCurrencyEnabled);
Configs__c conf = Configs__c.getInstance();
conf.Last_Run_Date__c = System.now();
conf.Multi_Currency_enabled__c = multiCurrencyEnabled;
Boolean isOpportunityTeamEnabled = isOpportunityTeamEnabled();
conf.Opportrunity_Team__c = isOpportunityTeamEnabled;
System.debug('isOpportunityTeamEnabled======'+isOpportunityTeamEnabled);
Boolean isOpportunitySplitEnabled = isOpportunitySplitEnabled();
conf.Opportunity_Split__c = isOpportunitySplitEnabled;
System.debug('isOpportunitySplitEnabled====>'+isOpportunitySplitEnabled);
if(conf != null){
update conf;
}
return true;
}
@AuraEnabled(cacheable=true)
public static Configs__c getConfigs() {
return Configs__c.getInstance();
}
@AuraEnabled(cacheable=true)
public static Boolean isOpportunityTeamEnabled() {
return Type.forName('Schema','OpportunityTeamMember') != null;
}
@AuraEnabled(cacheable=true)
public static Boolean isOpportunitySplitEnabled() {
return Type.forName('Schema','OpportunitySplit') != null;
}
}
<template>
<lightning-card title="Click Run Button To Check Below Configurations Enabled Or Not">
<div class="slds-m-around_medium">
<lightning-button label="Run" icon-name="utility:bundle_config" onclick={runCheck} variant="brand"></lightning-button>
<div>
<lightning-input type="checkbox" label="Multi Currency Enabled" checked={isMultiCurrencyEnabled} disabled></lightning-input>
<lightning-input type="checkbox" label="Opportunity Team" checked={isOpportunityTeamEnabled} disabled></lightning-input>
<lightning-input type="checkbox" label="Opportunity Split" checked={isOpportunitySplitEnabled} disabled></lightning-input>
<lightning-input type="datetime" label="Last Run Date" value={lastRunDate} readonly ></lightning-input>
</div>
</div>
</lightning-card>
</template>
import { LightningElement, track, wire } from 'lwc';
import checkAndUpdateMultiCurrency from '@salesforce/apex/ConfigController.checkAndUpdateMultiCurrency';
import getConfigs from '@salesforce/apex/ConfigController.getConfigs';
import { ShowToastEvent } from 'lightning/platformShowToastEvent';
import { refreshApex } from '@salesforce/apex';
export default class ShowConfig extends LightningElement {
@track resultMessage;
@track isMultiCurrencyEnabled;
@track isOpportunityTeamEnabled;
@track isOpportunitySplitEnabled;
@track lastRunDate;
@track wiredResult;
runCheck() {
checkAndUpdateMultiCurrency()
.then(result => {
this.isMultiCurrencyEnabled = result;
this.showSuccessToast();
//refresh
return refreshApex(this.wiredResult);
})
.catch(error => {
console.error('Error running multi-currency check', error);
});
}
@wire(getConfigs)
wiredConfigs(result) {
this.wiredResult = result;
if (result.data) {
const data = result.data;
this.isMultiCurrencyEnabled = data.Multi_Currency_enabled__c;
this.isOpportunityTeamEnabled = data.Opportrunity_Team__c;
this.isOpportunitySplitEnabled = data.Opportunity_Split__c;
this.lastRunDate = data.Last_Run_Date__c;
} else if (result.error) {
console.error('Error retrieving Configs__c', result.error);
}
}
showSuccessToast() {
const event = new ShowToastEvent({
title: 'Success',
message: 'Configurations updated successfully !!.',
variant: 'success',
});
this.dispatchEvent(event);
}
}
<?xml version="1.0"?>
<LightningComponentBundle xmlns="http://soap.sforce.com/2006/04/metadata">
<apiVersion>57.0</apiVersion>
<isExposed>true</isExposed>
<targets>
<target>lightning__RecordPage</target>
<target>lightning__AppPage</target>
<target>lightning__HomePage</target>
<target>lightning__Tab</target>
</targets>
</LightningComponentBundle>
Thank you for taking the time to read our blog! We appreciate your interest and hope you found valuable insights within these articles. If you have any questions, comments, or suggestions, we’d love to hear from you.