3

We have a managed package. In order to implement a sandbox / release management process for our application we have made all our code dynamic.

We populate via a custom setting the name of the org's namespace.

How do we implement a dynamic namespace for javascript remoting? http://www.salesforce.com/us/developer/docs/pages/Content/pages_js_remoting.htm

[namespace.]controller.method(
    [parameters...,]
    callbackFunction,
    [configuration]
);

Thanks in advance for your help.

5

The simplest way to have a conditional namespace in a remote action invocation is like this:

(namespace||window).controller.method(
   ...
);
|improve this answer|||||
2

I usually set a var on my VF page like this:

 var querySomething = '{!$RemoteAction.Ctl_SomeCtrl.querySomething}';

Then in my JS file:

Visualforce.remoting.Manager.invokeAction(
            querySomething,
            parameterToPass, 
            function(result,event) {
                //do stuff with result
            }
        );

You don't need to directly reference the namespace at all. You just can't use the JS remoting shorthand.

|improve this answer|||||
0

For those who stumble upon this post looking for any updates here is the SFDC recommended approach of doing this

|improve this answer|||||
  • Yep, thats basically what I did in my answer except I assigned the string to a variable. For me, I like having all my remoting calls assigned to variables so they're all in the same place, makes changing them easier. – Phil B Sep 13 '17 at 13:55
  • Ditto! Great minds ;) – Mohd Nadeem Shaikh Sep 15 '17 at 10:30

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.