Do not use JSON.stringify to pass params to Apex

Serializing parameters before passing them to Apex is considered bad practice because it leads to unclean code and negatively impacts performance.

Do NOT use JSON.stringify to pass params to Apex

Serializing parameters before passing them to Apex is considered bad practice because it leads to unclean code and negatively impacts performance.

Don't do this
@AuraEnabled
public static void call(String serializedParam) {
    MyWrapper wrapper = (MyWrapper) JSON.deserialize(serializedParam, MyWrapper.class);
    // ...
}
Don't do this
const params = {
    // ...
};

await call({
    serializedParam: JSON.stringify(params)
});

Apex data structures have corresponding equivalents in LWC that can be used directly. Please take a look at the table below for details.

APEX

LWC

Primitive Types e.g Boolean, String, Integer

Primitive Types

List<Type> e.g List<String>

Array [ ]

Custom Objects e.g Account, Custom__c

Object { }

Class e.g WrapperClass

Object { }

Map<Type, Type> e.g Map<String, String>

Object { }

Primitive Types

Do this
@AuraEnabled
public static void call(String stringParam, Integer integerParam) {
}
Do this
await call({
    stringParam: 'Some String',
    integerParam: 42
});

List<Type>

Do this
@AuraEnabled
public static void call(List<String> myList) {
    // ...
}
Do this
const stringArray = [
    'Some String 1',
    'Some String 2',
    'Some String 3',
];

await call({
    myList: stringArray
});

Custom Objects

Do this
@AuraEnabled
public static void call(Account account) {
    // ...
}
Do this
const newAccount = {
    Name: 'Account Name'
};

await call({
    account: newAccount
});

Wrapper Class

Do this
public class MyWrapper {
    @AuraEnabled
    public String myString {get; set;}
    @AuraEnabled
    public Integer myInteger {get; set;}
}
Do this
@AuraEnabled
public static void call(MyWrapper myWrapper) {
    // ...
}
Do this
const myWrapper = {
    myString: 'Some String',
    myInteger: 43
};

await call({
    myWrapper: myWrapper
});

Map<Type, Type>

Do this
@AuraEnabled
public static void call(Map<String, String> myMap) {
    // ...
}
Do this
const myMap = {
    param1: 'Some String 1',
    param2: 'Some String 2'
};

await call({
    myMap: myMap
});

Text and code were extracted from the original slide. Plain-text version of the whole catalog