5

I am trying to call a RemoteAction in an Apex Component. Every time I get the error 'unable to invoke action, no controller and/or method found'. I have reduced the function to one with only 1 string argument, and just pass down 'hello' when I call it, but it still does not work.

I am wondering if it has something to do with the fact that when the page loads I see this error from VFRemote.js

 Uncaught SecurityError: Blocked a frame with origin "https://c.cs15.visual.force.com"
 from accessing a frame with origin "https://cs15.salesforce.com". Protocols, domains,
 and ports must match. 

I had similar problems with actionfunctions, where they would not do anything if called from an included StaticResource. I am wondering if it is because the scripts and components are served from force.com, while the api is at salesforce.com

  • It might help to post your code or pseudocode to help us understand what is causing the error. – techbusinessman Nov 30 '14 at 23:23
  • This is a rather annoying limitation. I usually use a page to serve code from, but your millage may vary. Remember to use a decent cache duration for production environments to avoid excessive page calls. – sfdcfox Dec 1 '14 at 4:30
  • Could you please add the code snippet here? – the_phantom Jun 14 '15 at 11:55
  • Please post your code. Your javascript file could be hosted on yahoo.com, and it wouldn't matter because the origin in which the code runs is the origin of the domain that includes it, not the origin of where it is loaded from. Something else is going on here, not the location of the file. – Robert Sussland Jun 15 '15 at 1:04
1

You should use $Resource global variable when referencing static resources.

From salesforce docs:

It’s a best practice to reference static resources by using the $Resource global variable and the URLFOR() function instead of static strings. For example:

<apex:includeScript value="{!$Resource.MyJavascriptFile}"/>
<apex:image url="{!URLFOR($Resource.TestZip, 'images/Bluehills.jpg')}" width="50" height="50"/>

If you include your javascript resource using Resource or urlfor, it should resolve that error.

|improve this answer|||||
  • I included it that way, but it did not work. – Alex H Dec 1 '14 at 0:49
0

If you are calling the remoting action method in a component from your page level Javascript, you will get this issue - HOWEVER - you can have a remoting call within your page controller call a static method that exists within your component:

Controller:

@RemoteAction
global static List<Contact> getContactsRemote(){
    return MyComponent.getContacts();
}

Component Controller:

public static List<Contact> getContacts(){
    // your logic here...
    return [ your list of contacts here ]
}

That should work if you want to access some data specific to the component or accessing it via Remoting Call. However, for updating the component, you will need to have the Remoting call from javascript within the component.

<apex:component controller="componentController">
    <script src="source to your jQuery" ></script>

    <script>

         function myRemotingMethod( myparams ){
             Visualforce.remoting.Manager.invokeAction( '{!$RemoteAction.componentController.MyRemotingMethod}', myparams, function( result, event ){
                 // do some processing of your result here 
            });
         }
    </script>
</apex:component>

Component Controller:

    public class componentController{

        @RemoteAction
        globlal static .... MyRemotingMethod( String params ){
              ... do some stuff here 

           return ....;
        }
    }

and then access your stuff here for your component within the component.

|improve this answer|||||

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.