<template>
<div class="slds-grid slds-gutters slds-wrap">
<div class="slds-col slds-size_1-of-4">
<div class="slds-theme_shade">
<div class="slds-m-left_small slds-m-right_large">
<c-combo-box-cmp combo-box-options={objSelectionCombo} value={objValue} combo-label="Object"
oncombovaluechange={handleChangeObj}>
</c-combo-box-cmp>
</div>
<div class="slds-m-left_small slds-m-right_large slds-m-top_small">
<c-combo-box-cmp combo-box-options={recTypeSelectionCombo} value={recTypeValue} combo-label="Record Type"
oncombovaluechange={handleChangeRectype}>
</c-combo-box-cmp>
</div>
<div class="slds-m-left_small slds-m-right_large slds-m-top_small">
<lightning-input name="location" label="Location" class="slds-m-top_small"></lightning-input>
<lightning-button label="Search"></lightning-button>
</div>
</div>
<div class="slds-m-top_small">
<div class="slds-m-left_small">
<c-check-box-cmp map-checkbox-options={mapCheckboxOptions} value-check-box={valueCheckBox}
options-check-box={optionsCheckBox}>
</c-check-box-cmp>
</div>
</div>
</div>
<div class="slds-col slds-size_3-of-4">
</div>
</div>
</template>
public with sharing class ObjectAndRecTypeSelCC {
public ObjectAndRecTypeSelCC() {
}
@AuraEnabled(cacheable = true)
public static String getObjectList () {
List<String> objSelectionCombo = new List<String>();
List<Schema.SObjectType> gd = Schema.getGlobalDescribe().Values();
for(Schema.SObjectType objTyp : gd) {
String name = objTyp.getDescribe().getName();
if(!name.containsignorecase('history') && !name.containsignorecase('tag') &&
!name.containsignorecase('share') && !name.containsignorecase('feed') && !name.containsignorecase('ChangeEvent'))
{
objSelectionCombo.add(name);
}
}
objSelectionCombo.sort();
return JSON.serialize(objSelectionCombo);
}
@AuraEnabled(cacheable = true)
public static String getRecordTypes (String objApiName) {
System.debug('objApiName @@@@ ' + objApiName);
List<String> lstRTName = new List<String>();
if (objApiName != null) {
List<RecordType> lstRT = [SELECT Id, Name FROM RecordType WHERE SobjectType = :objApiName];
if (!lstRT.isEmpty()) {
for (RecordType rt : lstRT) {
lstRTName.add(rt.Name);
}
}
}
return JSON.serialize(lstRTName);
}
@AuraEnabled(cacheable = true)
public static string getCheckboxValues () {
Map<string, List<String>> mapCheckboxOptions = new Map<string, List<String>>();
mapCheckboxOptions.put('Commodity', fetchCheckboxOptions('Commodity'));
mapCheckboxOptions.put('Flexible', fetchCheckboxOptions('Flexible'));
return JSON.serialize(mapCheckboxOptions);
}
public static List<String> fetchCheckboxOptions (String strComboVal) {
List<String> lstCheckboxOptions = new List<String>();
if (strComboVal == 'Commodity') {
lstCheckboxOptions.add('Manufacturer');
lstCheckboxOptions.add('Corrugator');
lstCheckboxOptions.add('Sheet plant');
lstCheckboxOptions.add('Large RSC');
lstCheckboxOptions.add('Small RSC');
lstCheckboxOptions.add('Displays/POP');
lstCheckboxOptions.add('Triple wall');
lstCheckboxOptions.add('4+ colors');
lstCheckboxOptions.add('Micro flute');
lstCheckboxOptions.add('Speciality glue or die cut');
}
else if (strComboVal == 'Flexible') {
lstCheckboxOptions.add('Printer/Converter (checkbox)');
lstCheckboxOptions.add('Types of Materials (free text)');
lstCheckboxOptions.add('Styles of Materials (free text)');
lstCheckboxOptions.add('# of Layers (free text)');
lstCheckboxOptions.add('Ability to Perf (checkbox)');
lstCheckboxOptions.add('Print Processes (free text)');
lstCheckboxOptions.add('Surface Print/Reverse Print (free text)');
lstCheckboxOptions.add('# of Colors (free text)');
lstCheckboxOptions.add('In-House Graphics/Plates (checkbox)');
}
return lstCheckboxOptions;
}
}
/* eslint-disable no-console */
/* eslint-disable vars-on-top*/
/* eslint-disable guard-for-in*/
import {LightningElement, api, track, wire} from 'lwc';
import getObjectList from '@salesforce/apex/ObjectAndRecTypeSelCC.getObjectList';
import getRecordTypes from '@salesforce/apex/ObjectAndRecTypeSelCC.getRecordTypes';
import getCheckboxValues from '@salesforce/apex/ObjectAndRecTypeSelCC.getCheckboxValues';
export default class ObjectAndRecTypeSelectCmp extends LightningElement {
@api objSelectionCombo = [];
@api recTypeSelectionCombo = [];
@api objValue = '';
@api recTypeValue = '';
@api mapCheckboxOptions = [];
@api valueCheckBox = [];
@api optionsCheckBox = [];
@track error;
@wire(getRecordTypes, {objApiName: '$objValue'})
wiredRecordTypes ({error, data}) {
if (data) {
this.recTypeSelectionCombo = JSON.parse(data);
this.error = undefined;
} else if (error) {
this.error = error;
this.recTypeSelectionCombo = undefined;
}
}
connectedCallback () {
getObjectList ()
.then(result => {
console.log("Object List @@@@", result);
this.objSelectionCombo = JSON.parse(result);
})
.catch(error => {
this.error = error;
});
getCheckboxValues ()
.then(result => {
this.mapCheckboxOptions = JSON.parse(result);
})
.catch(error => {
this.error = error;
});
}
handleChangeObj (event) {
this.objValue = event.detail;
}
handleChangeRectype (event) {
this.recTypeValue = event.detail;
for (var key in this.mapCheckboxOptions) {
if (key === this.recTypeValue)
this.optionsCheckBox = this.mapCheckboxOptions[key];
}
}
}