1

I'm working in a managed package and I want to use the less references to the namespace (CI proposes ).

For now I would like to know if it's possible to get records from my controller in my javascript code without the namespace in a remote action. for example:

Method in controller:

@RemoteAction
public String getAccountInformation(){
    return JSON.serialize([Select Id,Name,my_custom_field from Account]);
}

function in my javascript file:

function loadAccounts(){
    my_namespace.MyController.getAccountInformation(function(result,event){
        if(event.status){
            var array = JSON.parse(result.replace(/(&quot\;)/g,"\""));
            //Here My loop over the array
            //here my array returns namespace__my_custom_field **************   
        }
    });
}

I would like something that returns the value without to create and assign the values to a wrapper class in the controller.

1
  • 1
    I'm not sure, but I think this is a use case for apex:remoteObjects. Have you tried that instead?
    – sfdcfox
    Apr 28 '17 at 19:30
0

To make your visualforce page Javascript remoting independent of namespace use the below syntax

 Visualforce.remoting.Manager.invokeAction(
        '{!$RemoteAction.MyController.getAccountInformation}',
        function(result, event){
            if (event.status) {

            } else if (event.type === 'exception') {

            } else {

            }
        }, 
        {escape: true}
    );

Here is the document from SFDC for reference .As per docs the namespace is automatically taken care.

However if you have custom field names I think you will need to still handle the field namespaces ,In that case you can write an apex class to get the namespace and use a remote action first to get the namespace and store as a global variable and then use that to append to all the custom fields .

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.