[SalesForce] Javascript remoting not hitting apex

I'm trying to call an Apex function from a Visualforce page, but my Apex function isn't getting hit. What am I doing wrong?

I have this

ct_4_sf.RecordingTest.saveRecording(
    paths,
    function(data){
        console.log('data is ',data);
    }
);

Which is supposed to call this:

public with sharing class RecordingTest {

    @RemoteAction
    public static String saveRecording(String data) {
        System.debug('hit save recording' + data);
        return Connector.saveRecording(data);
    }
}

But the System.debug line never gets hit.

I've also tried it this way

Visualforce.remoting.Manager.invokeAction(
    '{ct_4_sf.RecordingTest.saveRecording}',
    paths,
    function(data){
        console.log('data is ',data);
    }
);

with the same result.

For this method, using !$RemoteAction instead of, or in front of ct_4_sf gives me compilation errors. Removing ct_4_sf(which is the namespace under Setup > Create > Packages), from the first method doesn't help.

I'm not getting any errors in the console or anywhere else.

Best Answer

The problem is with this line right here:

'{ct_4_sf.RecordingTest.saveRecording}',

You should be using the $RemoteAction merge value, like this:

'{!$RemoteAction.RecordingTest.saveRecording}',

This automatically takes care of your namespacing problems, too.

Your controller won't be available unless you include it as a controller or extension on the page. You don't automatically get all remote actions for free.

Related Topic