Does anyone know how to do this? I've tried just about everything, but can only successfully call an apex method that has a single parameter using LCC.callApex(...)
. The docs describe apexMethodParameters
as "A JSON array of arguments for the Apex method", yet all examples I can find show apex methods with just a single parameter and the corresponding call to LCC.callApex
being provided a string representing an atomic value, not an array.
For example, this works for calling an apex method with a single parameter of type string
:
LightningContainer.callApex(
"LightningContainerTest.getTenAccountsThatStartWith",
"someString",
handlerFunction,
{ escape: true }
);
However, to call a method with the following signature:
@RemoteAction
public static List<Account> getAccounts(string accountName, integer maxRecords) {...}
Nothing seems to work. Things I've tried:
LightningContainer.callApex(
"LightningContainerTest.getTenAccountsThatStartWith",
["someString" 10],
handlerFunction,
{ escape: true }
);
LightningContainer.callApex(
"LightningContainerTest.getTenAccountsThatStartWith",
{ accountName: "someString", maxRecords: 10 },
handlerFunction,
{ escape: true }
);
and even, ridiculously:
LightningContainer.callApex(
"LightningContainerTest.getTenAccountsThatStartWith",
[{ someString: "someString" }, {maxRecords: 10 }],
handlerFunction,
{ escape: true }
);
While only some of these can be correctly described as JSON arrays, they are all more JSON-y than the working example from the docs (as a plain string isn't JSON or an array - unless you want to get technical and call it an array of chars). In any case, I'm just starting to think Salesforce didn't really think this one out very well and it simply doesn't work. The analogous JavaScript code for accomplishing the same thing in Visualforce shows something that won't work here, and I'm guessing the lightning-container npm package was cobbled together quickly, was not widely tested, was never widely adopted, and thus this just doesn't work and was never fixed.
My current solution is to just serialize an object into a string and deserialize it in the apex controller when I need multiple parameters, but would be grateful if anyone can share their experience of solving this differently.