3

Given

Apex controller

@AuraEnabled
public static String saveAppSetting(AppSetting__c config)
{
    if (config == null) {
        throw new AuraHandledException(System.Label.NO_DATA);
    }

    // skipped for brevity
    return 'success';
}

Aura component helper

saveAppSetting: function(component) {
    const action = component.get("c.saveAppSetting");
    action.setParam("config", null);
    action.setCallback(this, function(response) {
        const state = response.getState();
        if (state === "SUCCESS") {
            console.log("Success");
        } else {
            console.error("Error");
        }
    });

    $A.enqueueAction(action);
}

When I execute this in a scratch org with a namespace, everything is fine. When this code runs in a subscriber org inside an installed managed packed, this ends up with the following error:

enter image description here

It doesn't get to this if (config == null) line on server, so it must break during deserialization and this is out of developer reach. Has anyone had such issues and does anybody know how to address it?

6

The standard workaround for this is to use a normal String parameter instead:

@AuraEnabled
public static String saveAppSetting(String configJson)
  AppSetting__c config = (AppSetting__c)
    JSON.deserialize(configJson, AppSetting__c.class);

action.setParam("configJson", JSON.stringify(null)); // Or an Object

In the meantime, you might want to report the bug to Support. As far as I can tell, this should work, it's just a glitch in the platform.

1

I think issue might be with namespace of object.

@AuraEnabled
public static String saveAppSetting(namespace__AppSetting__c config)

Try by adding namespace in auraenabled parameters. I think fields are passed with namespace but if not Pass fields also with namespace from lightning component.

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.