Monday, 9 July 2012

JavaScript Remoting Example

JavaScript remoting in Visualforce provides support for methods in Apex controllers to be called via JavaScript. This allows you to create pages with complex, dynamic behavior that isn’t possible with the standard Visualforce AJAX components. There are three aspects to JavaScript remoting:

1. The remote method invocation you add to the Visualforce page, written in JavaScript.

2. The remote method definition in your Apex controller class, written in Apex, but there are few differences from normal action methods.

3. The response handler callback function you add to or include in your Visualforce page, written in JavaScript.

VFP Page


    

    
    
    
    

Class


global class TEZ_AC_RemoteActionExample {
    //Variables
    public String accountName { get; set; }
    public static Account account { get; set; }
    
    // constructor
    public TEZ_AC_RemoteActionExample() { }  
    
    //Remote Action
    @RemoteAction
    global static Account getAccount(String accountName) {
        account = [SELECT Id, Name, Phone, Type, NumberOfEmployees FROM Account WHERE Name = :accountName];
        return account;
    }
}



No comments:

Post a Comment