0

I want to create a record with e.force:createRecord. I want to create the default fields values in apex logically, then pass them back to the JS controller to be used in defaultfieldValue property as JSON. What's the best way to do this ? :

    createWA : function(component,fields){
    var createWA = $A.get('e.force:createRecord');

    if(createWA){

        var defualts = JSON.stringify(fields);

        createWA.setParams({
            "entityApiName":"Waste_Assessment__c",
            "recordTypeId": fields['rectypeid'],
            "defaultFieldValues":default
        });

I'm creating the field list here in apex using a Map:

     public static Map<String,String> init(String oppid){        
        Map<String,String> fields = new Map<String,String>();

this didn't work when the e.force:createRecord window appeared it said:

Looks like there's a problem.

Unfortunately, there was a problem. Please try again. If the problem continues, get in touch with your administrator with the error ID shown here and any other related details.

2
  • 2
    Please check the spelling in your code. If this question is correctly copy-pasted, you have some typos in your code, which could cause this error. – sfdcfox Mar 8 '19 at 21:35
  • 1
    There also is a lot of missing code, including how the apex is sent to the JS side and how the event is actually fired. – Sebastian Kessel Mar 8 '19 at 22:23
1

defaultFieldValues is a Map data type. This means that you should not be attempting to stringify the object. Simply pass the object in directly as an object; the platform will take care of the rest for you.

2
  • So if you return a map from apex you get a map in JS ? – SallyRothroat Mar 9 '19 at 13:36
  • 1
    @SallyRothroat Yes, that's right. – sfdcfox Mar 9 '19 at 16:43

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.