Activity › Forums › Salesforce® Discussions › What is the use of Remote Action notation in Salesforce?
Tagged: Help & Training, Remote Action, Salesforce Example
-
What is the use of Remote Action notation in Salesforce?
Posted by shariq on July 26, 2017 at 11:19 AMWhat is the basic definition Remote Action notation?Please give the example.
Parul replied 7 years, 8 months ago 3 Members · 2 Replies -
2 Replies
-
Hello Shariq,
The RemoteAction annotation provides support for Apex methods used in Visualforce to be called via JavaScript. This process is often referred to as JavaScript remoting.
you can refer this link:
- [adinserter block='9']
-
The RemoteAction annotation is used in Visualforce page then it is called via JavaScript.
Ex:
global with sharing class AccountRemoter {
public String accountName { get; set; }
public static Account account { get; set; }
public AccountRemoter() { } // empty constructor@RemoteAction
global static Account getAccount(String accountName) {
account = [SELECT Id, Name, Phone, Type, NumberOfEmployees
FROM Account WHERE Name = :accountName];
return account;
}
}<script type=”text/javascript”>
function getRemoteAccount() {
var accountName = document.getElementById(‘acctSearch’).value;Visualforce.remoting.Manager.invokeAction(
‘{!$RemoteAction.AccountRemoter.getAccount}’,
accountName,
function(result, event){
if (event.status) {
// Get DOM IDs for HTML and Visualforce elements like this
document.getElementById(‘remoteAcctId’).innerHTML = result.Id
document.getElementById(
“{!$Component.block.blockSection.secondItem.acctNumEmployees}”
).innerHTML = result.NumberOfEmployees;
} else if (event.type === ‘exception’) {
document.getElementById(“responseErrors”).innerHTML =
event.message + “<br/>\n<pre>” + event.where + “</pre>”;
} else {
document.getElementById(“responseErrors”).innerHTML = event.message;
}
},
{escape: true}
);
}
</script>THanks
Log In to reply.