function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
LB_DDLB_DD 

Page with one controller and RemoteAction on another

Hello,

 

I want to know (I can info about this) if I can have a Visualforce page with a controller and on that page a @RemoteAction with another controller, similar to this:

 

   VISUALFORCE PAGE:

<apex:page standardStylesheets="false" docType="html-5.0" sidebar="false" showHeader="false" contentType="text/html" cache="true" controller="MyPageControllerClass">

<apex:composition template="TemplateFB">
  <head>
  </head>
<apex:form id="signUpForm">
  <input type="text" name="Id" id="Id" />
  <a href="#" onclick="javascript&colon;signUp(); return false;">Click Me</a>
  <div id="processing"></div>
</apex:form>

<script>
function signUp()
{
   var str = '';
   try{
      str = document.getElementById('Id').value;
   }catch(e){}
   MyGlobalClass.SaveId(str , function(Result, event)
   {
        console.log('Result',Result);
        console.log('event',event);
        if (event.status)
        {
          document.getElementById('processing').innerHTML = 'Information updated.';
        }else{
          document.getElementById('processing').innerHTML = 'Problem!';
        }
   }, {escape:true});
}
</script></apex:composition></apex:page>

  GLOBAL CLASS to manage @RemoteAction call:

global with sharing class MyGlobalClass {
  
    @RemoteAction
    global static String SaveId(string dataString)
    {
        String res = '';
        MyPageControllerClass myc = new MyPageControllerClass();        
        
        try
        {
           res = myc.SaveRecord(dataString);  
        }
        catch(exception e)
        {
            res = 'error';
        }

        return res;
    }
}

   And my Controller on Visualforce page (and call exist a method called by the RemoteAction):

public with sharing class MyPageControllerClass
{

  public String OneMethod(){
   String t = 'one thing';
   return t;
  }

  public String SaveRecord(){
   String t = 'success';
   return t;
  }

}

 

 

With Chrome console I saw:

 

Uncaught ReferenceError: MyGlobalClass is not defined

 

:(

 

I need to use the code inside a iFrame.

I put on the "Sites" permission, all controllers available.

 

Anyone have idea if I can use a controller for the vf page and inside use @RemoteAction with another class?

 

 

Best Regards,

LB

 

 

 

Best Answer chosen by Admin (Salesforce Developers) 

All Answers

LB_DDLB_DD

Hello,

 

Anyone have an idea about this?

 

Best Regards,

LB

LB_DDLB_DD
This was selected as the best answer