how to use dynamic field and dynamic value as a default value
Sourabh42 opened this issue · comments
Summary
how to add dynamic value and dynamic field in navigation state context
Salesforce Org Type
Developer Edition Org
Steps To Reproduce
No response
Current Behavior
No response
Expected Behavior
No response
Relevant Log Output
No response
Code of Conduct
- I agree to follow this project's Code of Conduct
Welcome! 👋
Thank you for posting this issue. 🙇🏼♂️ We will come back to you latest within the next 48h (working days). Stay tuned!
Hi @Sourabh42, Thank you for the idea. We will review and implement it.
Hi @Sourabh42 - The defaultValues
is just a JavaScript object with field names as keys, and field values as values. So you should be able to dynamically create or modify that JavaScript object before passing it to the Navigate function.
For example, here is how you could modify the NavToNewRecordWithDefaults recipe to send dynamic fields and values.
export default class NavToNewRecordWithDefaults extends NavigationMixin(
LightningElement
) {
// An object that stores default values for the sObject
obj = {
FirstName: 'Morag',
LastName: 'de Fault',
};
companyName = 'Demo';
newFieldName = 'Company';
connectedCallback(){
// Dynamically adding a static field name and value
this.obj.LeadSource = 'Other';
this.obj.LastName = 'Some other name';
// Dynamically adding a dynamic field name and value
this.obj[this.newFieldName] = this.companyName;
}
navigateToNewContactWithDefaults() {
const defaultValues = encodeDefaultFieldValues(this.obj);
Hope this answers your question. If not, please elaborate on your question and I'll be happy to help.
I hope the above answer is helpful. As there is no further reply for a while closing this issue.