Based on your question, it seems you need to populate predefined set of fields everytime when record is inserted or updated. So You can create Field set on that object and fetch fields in apex using Schema methods. Schema.FieldSet fSet = Schema.getGlobalDescribe().get(ObjectName).getDescribe().FieldSets.getMap().get(fieldSetName);
Let say you want to do this activity for Account. Basically either it's Insert or Update, goal is to populate set of fields before DML. Creating new instance here. Account accountRec = new Account(); for (Schema.FieldSetMember fsm : fSet.getFields()) { //iterate over all fields in fieldset accountRec.put(fsm.getFieldPath(), VALUE); //getFieldPath() will return API name of the field } insert accountRec; Similar approach can be taken for update as well.
Refer the below links have solution for similar kind of ask. https://metillium.com/2017/08/lightning-field-set-form-component/ https://pantherschools.com/how-to-use-field-set-in-lightning-component/
If this information helps, Please mark it as best answer.
Based on your question, it seems you need to populate predefined set of fields everytime when record is inserted or updated. So You can create Field set on that object and fetch fields in apex using Schema methods. Schema.FieldSet fSet = Schema.getGlobalDescribe().get(ObjectName).getDescribe().FieldSets.getMap().get(fieldSetName);
Let say you want to do this activity for Account. Basically either it's Insert or Update, goal is to populate set of fields before DML. Creating new instance here. Account accountRec = new Account(); for (Schema.FieldSetMember fsm : fSet.getFields()) { //iterate over all fields in fieldset accountRec.put(fsm.getFieldPath(), VALUE); //getFieldPath() will return API name of the field } insert accountRec; Similar approach can be taken for update as well.
Based on your question, it seems you need to populate predefined set of fields everytime when record is inserted or updated.
So You can create Field set on that object and fetch fields in apex using Schema methods.
Schema.FieldSet fSet = Schema.getGlobalDescribe().get(ObjectName).getDescribe().FieldSets.getMap().get(fieldSetName);
Let say you want to do this activity for Account.
Basically either it's Insert or Update, goal is to populate set of fields before DML.
Creating new instance here.
Account accountRec = new Account();
for (Schema.FieldSetMember fsm : fSet.getFields()) { //iterate over all fields in fieldset
accountRec.put(fsm.getFieldPath(), VALUE); //getFieldPath() will return API name of the field
}
insert accountRec;
Similar approach can be taken for update as well.
Please mark this as Best Asnwer if it helps!
Regards,
Darshit Pathak
All Answers
Refer the below links have solution for similar kind of ask.
https://metillium.com/2017/08/lightning-field-set-form-component/
https://pantherschools.com/how-to-use-field-set-in-lightning-component/
If this information helps, Please mark it as best answer.
Thanks!!
Based on your question, it seems you need to populate predefined set of fields everytime when record is inserted or updated.
So You can create Field set on that object and fetch fields in apex using Schema methods.
Schema.FieldSet fSet = Schema.getGlobalDescribe().get(ObjectName).getDescribe().FieldSets.getMap().get(fieldSetName);
Let say you want to do this activity for Account.
Basically either it's Insert or Update, goal is to populate set of fields before DML.
Creating new instance here.
Account accountRec = new Account();
for (Schema.FieldSetMember fsm : fSet.getFields()) { //iterate over all fields in fieldset
accountRec.put(fsm.getFieldPath(), VALUE); //getFieldPath() will return API name of the field
}
insert accountRec;
Similar approach can be taken for update as well.
Please mark this as Best Asnwer if it helps!
Regards,
Darshit Pathak