0

I have a requirement where I need to set the defaultFieldValues dynamically (both field name & value). How can I achieve that?

var createRecordEvent = $A.get('e.force:createRecord');
if ( createRecordEvent ) {
    createRecordEvent.setParams({
        'entityApiName': 'Account',
        'defaultFieldValues': {
            'Name' : 'John',
            'XYZ__C' : '123',
        }
    });
    createRecordEvent.fire();
}
5
  • What have you tried so far?
    – Jayant Das
    Commented Jun 13, 2019 at 13:12
  • u r values what of type of format like collection(sobject)/Map?
    – sdandamud1
    Commented Jun 13, 2019 at 13:34
  • am getting the values from apex as Map<String,String> Commented Jun 13, 2019 at 13:36
  • @JayantDas - i tired by passing as createRecordEvent.setParams({ varJSON}) varJSON =dynamical values from apex. Commented Jun 13, 2019 at 13:38
  • can you post the structure after use this JSON.stringify(your value of Map<String,String) ?
    – sdandamud1
    Commented Jun 13, 2019 at 14:23

1 Answer 1

1

You can declare accounts as object. You can replace accounts values from your mapped object.

var accounts={ Name: 'John', XYZ__C : '123'};
var createRecordEvent = $A.get('e.force:createRecord');
if ( createRecordEvent ) {
    createRecordEvent.setParams({
        'entityApiName': 'Account',
        'defaultFieldValues': accounts
    });
    createRecordEvent.fire();
}
1
  • yea i followed the same ,its worked.thank you all. Commented Jun 19, 2019 at 9:16

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .