0

I'm working on a button that clones a record and would like to be able to dynamically populate field values into the force.createRecord form. This was the only way i've found that will keep page layouts and allow easy editing of fields before saving record. I'm stuck on how to convert a Map<String, Object> into a String that will work with the defaultValues parameter. If anyone has a sample code of how to do this it would be much appreciated. Thanks

Create map between api and record value

Object obj = [SELECT Id, recordtypeId, Name From ObjLIMIT limit 1];


Map<String, Object> fieldsAPINameToValue = objServiceContract.getPopulatedFieldsAsMap();

force:createRecord - setting default values dynamically

var accounts={fieldsAPINameToValue};
var createRecordEvent = $A.get('e.force:createRecord');
if ( createRecordEvent ) {
    createRecordEvent.setParams({
        'entityApiName': 'Account',
        'defaultFieldValues': accounts
    });
    createRecordEvent.fire();
}

Now this doesn't populate any values because the format is not correct. I tried to serialize the response but instead of getting fields and values in a nice json format i get users and URL's. So i'm guessing this is not possible from this method

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.