Javascript Remoting for APEX controller

Javascript remoting is the process that provides support for some methods in APEX controllers to be called via Javascript.The @RemoteAction annotation is currently available as a Developer preview.You have to contact Salesforce.com support to enable this feature.To use Javascript remoting, your request must take the following form:
[<namespace>.]<controller>.<method>([params...,] <callbackFunction>(result, event)
{
// callback function logic
}, {escape:true});
  • namespace is your organization's namespace. This is only required if the class comes from an installed packaged.
  • controller is the name of your Apex controller
  • method is the name of the Apex method you're calling
  • params is the comma–separated list of parameters that your method takes
  • callbackFunction is the name of the function that handles the response from the controller. It returns the status of the call and the method result.
  • escape defines whether your response should be escaped (by default, true) or not (false)
In controller, your Apex method declaration is preceded with the @RemoteAction annotation like this:

@RemoteAction
global static String getItemId(String objectName) { ... }
Example code:

/*VF page*/

<script type="text/javascript">
function updateStatus(input,id) {
var inputStatus=id;
shortList.doShortListThroughCheck(inputStatus,function(result,event){
if(input.checked){
document.getElementById(id).value="Short Listed";
alert(document.getElementById(id).value);
}else{
document.getElementById(id).value="New";
alert(document.getElementById(id).value);
}
},{escape:true});
}</script>
/*@VF Component*/
<apex:selectCheckboxes onclick="updateStatus(this,'{!app.Name}');">
</apex:selectCheckboxes>
/*In Controller*/
@RemoteAction
global static Applicant__c doShortListThroughCheck(String para){
Applicant__c applicant;
try{
applicant=[select Name, Name__c, Status__c from Applicant__c where Name =:para limit 1];
applicant.Status__c='Short Listed';
update applicant;

}catch(DMLException e){
ApexPages.addMessages(e);
return null;
}
return null;
}

Comments

  1. hI I AM NEW TO SALESFORCE. So could you please tell me about the visuval force,apex,governor limits

    ReplyDelete
    Replies
    1. Go to Developerforce sites, and make friendship with Google ....;)

      Delete

Post a Comment

Popular posts from this blog

Parameter passing using Javascript+actionFunction in visualforce

Displaying pop-up summaries on hover in visualforce