I am trying to populate an LWC form using field sets.
Currently I am populating a combo box with metadata records
Call Class to populate combo box and FieldSet
@AuraEnabled (cacheable=true)
public static List<objectFieldSet__mdt> getCmtFS(){
return [SELECT Id, DeveloperName,fsName__c FROM objectFieldSet__mdt];
}
Combo box HTML
<lightning-card title="">
<lightning-combobox
name="Select:"
label="Select:"
placeholder="Choose an Object"
value={value}
onchange={handleCbupdate}
options={object}>
</lightning-combobox>
<p></p>
</lightning-card>
Combo box JS
@wire(getCmtFsData)
wiredCmtObjectsData({ error, data }) {
if (data) {
for(i=0; i<data.length; i++) {
this.items = [...this.items ,{value: data[i].DeveloperName , label: data[i].DeveloperName} ];
}
this.error = undefined;
} else if (error) {
this.error = error;
}
}
get object() {
return this.items;
}
Call Class to get fields for field set.
gif( this.chosenValue == 'Account'){
this.renderAccount = true;
getAccountFieldSet()
.then(result => {
this.accounts = JSON.parse(result);
this.error = undefined;
})
.catch(error => {
this.error = error;
this.accounts = undefined;
}
Field set Apex Class return fields in field set via a JSON string
public static String getAccountFieldList() {
Map<String, String> returnFS = new Map<String,String>();
List<Schema.FieldSetMember> listFieldSetFields =
Account.getSObjectType().getDescribe().fieldSets.getMap().get('RecordCreation').getFields();
returnFS.put('FIELDSET_LIST', JSON.serialize(listFieldSetFields));
return JSON.serialize(returnFS);
There is an Account, Contact, Invoice__c, Payment__c cmt records and each has a field set.
How can I used the fields returned from the apex class to populate a form for each object? These fields are all input fields
Best Answer
Solution to getting fields set to render
HTML
JS
Apex Class