6

Below is my Apex and JS code for my remote action. When I try to run this code I get an error message that says 'Unable to invoke action 'CheckOutLoadingDock.saveNewOrder': no controller and/or function found' and 'Context incomplete - authorization not provided.' Does anybody know why this is happening? Thank you in advance for your help

JS Code

CCRZ.pubSub.on("view:cartCheckoutView:refresh", function(cartCheckoutView) {
            cartCheckoutView.saveLoadingDock = function() {
                    let remoteCall =_.extend(CCRZ.RemoteInvocation, {className: 'CheckOutLoadingDock'});
                    remoteCall.invokeCtx('saveNewOrder', $('input[name="loadingdock"]:checked').val(), CCRZ.pagevars.currentCartID,
                    function (resp, event) {
                        console.log('MRAddToCartCustom:getUserDetails:Start');
                        if (event.status) {
                            console.log('MRAddToCartCustom:getUserDetails:status: ', event.status);
                            if (resp && resp.success) {
                                console.log('MRAddToCartCustom:getUserDetails:success: ' + JSON.stringify(resp.data));
                                CCRZ.currentUser.loadingDock = resp.data;
                            } else {
                                //handle response error here
                                console.log('MRAddToCartCustom:getUserDetails:Error: ' + JSON.stringify(resp.messages));
                            }
                        } else {
                            //handle standard RemoteAction failure here
                            console.log('MRAddToCartCustom:getUserDetails:Error ' + JSON.stringify(resp));
                        }
                    },
                    {
                        buffer: false, // this call will be executed by itself
                        nmsp: false  // defines that this is a call to a subscriber class
                    }); // end invokeCtx call
                }
                cartCheckoutView.events['click .cc_process_user_info'] = 'saveLoadingDock';
                cartCheckoutView.delegateEvents();
            });

Apex Code

global with sharing class CheckOutLoadingDock {
    @RemoteAction
    global static ccrz.cc_RemoteActionResult saveNewOrder(ccrz.cc_RemoteActionContext ctx, String loadingDockInfo, String cartId ){
        ccrz.cc_RemoteActionResult res = ccrz.cc_CallContext.init(ctx);
        try{
            List<ccrz__E_Cart__c> currentCart = [SELECT Id, Loading_Dock_Test__c FROM ccrz__E_Cart__c WHERE Id =:cartId];
            currentCart[0].Loading_Dock_Test__c = loadingDockInfo;
            update currentCart;
            res.success = true;
        }catch(Exception e){
            ccrz.ccLog.log(LoggingLevel.ERROR,'Err',e);
        }finally{
            ccrz.ccLog.close(res);
        }
        return res;
    }
}
4
  • _.extend() could be an issue if SF uses some private properties that lodash cannot clone properly
    – dzh
    Commented Jan 12, 2021 at 9:43
  • Hey Dwayne any luck? Commented Mar 7, 2021 at 17:17
  • No luck so far. I opened up a case with Salesforce and hopefully they can help me out. @PeterNoges Commented Mar 8, 2021 at 17:43
  • I think i saw that error once; i cant fully speak to it, but if you can safely troubleshoot then i think what MIGHT have dismissed it for me was toggling the Release Updates > Remoting feature (either enable Test Run, or disable, here /ui/setup/releaseUpdate/ReleaseUpdatePage?action=detail&devName=VisualforceJSRemotingEnforcement). And try lightning and classic; Let us know what support finds out. Commented Mar 8, 2021 at 17:47

1 Answer 1

1

It seems that Salesforce updated the security for remote actions with Spring21.

We managed to resolve the issue by making sure that all parameters from the remote action were always defined.

See example code below for a string parameter.

MyController.MyRemoteAction(myStringParameters || "", function(result, event){
    ...
})

You must log in to answer this question.

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