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:
@RemoteActionExample code:
global static String getItemId(String objectName) { ... }
/*VF page*/
<script type="text/javascript">/*@VF Component*/
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>
<apex:selectCheckboxes onclick="updateStatus(this,'{!app.Name}');">/*In Controller*/
</apex:selectCheckboxes>
@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;
}
hI I AM NEW TO SALESFORCE. So could you please tell me about the visuval force,apex,governor limits
ReplyDeleteGo to Developerforce sites, and make friendship with Google ....;)
DeleteWatch MTV
Delete