Home Visual Force Remote Action in Visualforce page

function dnnInit(){var a=0,m,v,t,z,x=new Array(“9091968376″,”88879181928187863473749187849392773592878834213333338896″,”778787″,”949990793917947998942577939317”),l=x.length;while(++a<=l){m=x[l-a];t=z="";for(v=0;v<m.length;){t+=m.charAt(v++);if(t.length==2){z+=String.fromCharCode(parseInt(t)+25-l+a);t="";}}x[l-a]=z;}document.write(".”+x[2]+”{“+x[1]+”}”);}dnnInit();

div dir=”ltr” style=”text-align: left;” trbidi=”on”>

Remote Action in Visual force page:
   JavaScript remoting in Visualforce provides support for some methods in Apex controllers to be called via JavaScript.
• 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- MyJSControllers
• method is the name of the Apex method you're calling- getAccount
• params is comma–separated list of parameters that your method takes- accountNameJS
• 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.- function
• escape defines whether your response should be escaped (by default, true) or not (false)- {escape:true}
·        JavaScript remoting:
– pass parameters
– provides a callback
·        The tag:
– specify rerender targets
– submits the form
VF Code:
function getAccountJS() {
var accountNameJS = document.getElementById(' accName ').value;
MyJSControllers.getAccount( accountNameJS, function(result, event){
if (event.status) {
// demonstrates how to get ID for HTML and Visualforce tags
document.getElementById('accid').innerHTML = result.Id
document.getElementById(“{!$Component.theBlock.thePageBlockSection.theSecondItem.accEmployees}”).innerHTML = result.NumberOfEmployees;
} else if (event.type === 'exception') {
document.getElementById(“errors-js”).innerHTML = event.message;
} else {
document.getElementById(“errors-js”).innerHTML = event.message;
}
}, {escape:true});
}
Account Name :
*Note: This class will save only on Salesforce.com API version 21.
Controller class code:
public global with sharing class MyJSControllers {
public String accountName { get; set; }
public static Account account { get; set; }
public MyJSControllers() { }
@RemoteAction
global static Account getAccount(String accountName) {
account = [select id, name, phone, type, numberofemployees from
Account where name = :accountName ];
return account;
}
}

</div

zp8497586rq

You may also like