[SALESFORCE] Remote Action function in Visualforce Page (ok)
https://webkul.com/blog/remote-action-function-visualforce-page/
What is Remote Action function in Salesforce?
Remote action function in salesforce allows user to access any method from any class through javasrcipt methods, and get the result as a javascript object for further manipulation.
Points to remember while implementing remote action function:
Remote action method should have @RemoteAction annotation.
The method should also be Global and Static
Let’s start with controller code:
global with sharing class ContactJs {
/**
* Webkul Software.
*
* @category Webkul
* @author Webkul
* @copyright Copyright (c) 2010-2016 Webkul Software Private Limited (https://webkul.com)
* @license https://store.webkul.com/license.html
*/
public ContactJs() { } // empty constructor
@RemoteAction //the function to be called in remote action should use this annotation
global static list<Contact> getcon() {
//function should be static and global else it will throw error
list<Contact> con1 = [SELECT id,name FROM contact limit 5];
if(con1!=null && !con1.isEmpty()){
return con1;
}else{
return new list<contact>();
}
}
}Now the Visualforce Page:

Last updated
Was this helpful?