7

Assume we have this code in the controller or helper to invoke a APEX method:

action = cmp.get("c.TestUwe");
action.setParams( { params :  ['777','888'] } );
action.setCallback( null, function(callbackResult) {
    if(callbackResult.getState()=='SUCCESS') {
        var result = callbackResult.getReturnValue();
        console.log('RESULT', result  );
    }
    if(callbackResult.getState()=='ERROR') {
        console.log('ERROR', callbackResult.getError() ); 
    }
});
$A.enqueueAction( action );

In Apex we have one input param of List<Object>:

@AuraEnabled public static Object TestUwe(List<Object> params) {
    system.debug( params );
    return null;
}   

All good: this works fine!

Now if I change the type to just Object

@AuraEnabled public static Object TestUwe(Object params) 

It does not work anymore:

An internal server error has occurred↵Error ID: 1556564141-71620 (-2109904195)↵↵org.auraframework.throwable.AuraExecutionException: apex://elfLC_WorkOrderLineItemEditor: java.lang.UnsupportedOperationException↵ at ...

Other example is: we keep List<Object> in APEX but provide this as params:

action.setParams( { params :  ['777','888', { test : 'abc' }] } );

An internal server error has occurred↵Error ID: 1556564141-71801 (119852647)↵↵org.auraframework.throwable.AuraExecutionException: apex://elfLC_WorkOrderLineItemEditor: common.apex.runtime.impl.ExecutionException: Salesforce System Error: 1556564141-71800 (-1664928234) (-1664928234)↵ at ...

So not all possible types works as expected.

I've read these chapters but can't find any documentation on which types are supported and which not. Where does Salesforce specify EXACTLY what is allowed and what not?

I found some posts where people serialize the parameters, e.g.:

Why is this necessary at all? Why can't the framework just do the serialization of anything on it's own and in APEX we just use the typeless Object and take care on proper handling from there dynamically?

But the main question is:

Where do I find the official documentation on which types are allowed and which are forbidden? It should be stated at a prominent place here in order to save us a lot of trial-and-error time.

4
  • Interested to see if you get an official answer on this. Nothing except string seems to work reliably, see also this: salesforce.stackexchange.com/questions/108355/…
    – Aidan
    Commented Sep 7, 2017 at 14:08
  • @Aidan missing docs on this would by very bad, because it's wasting a lot of developers time for nothing... I always think: it's me not reading the right place....
    – Uwe Heim
    Commented Sep 7, 2017 at 14:18
  • I'd assumed that they meant the parameter types to work the same way as the return types, which they list here: developer.salesforce.com/docs/atlas.en-us.lightning.meta/… But, as in by previous link, Integers don't work correctly. And I've found that collections of collections don't work right as a return value.
    – Aidan
    Commented Sep 7, 2017 at 14:24
  • I cant check it now but will propose to try for: { params : ['777','888'] } - Map<String, List<string>>
    – patryk
    Commented Oct 4, 2017 at 11:28

1 Answer 1

2

From my experience, the best practice for passing parameter from Lightning component to Apex class is to use JSON.stringify() on anything that is more complicated than single string (every list, map, object, map of lists, ...). You can then deserialize/parse it in apex, which is safer then managing it in javascript.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .