What is Getter and Setter Method in VF page

Getter and Setter Method, we use to call apex method from Ajex without using remote action or RestResource API.

We can directly retrieve values in a visualforce page from Apex controller. when we are using the keyword "Get" before a variable example "getCompnayName"
now "Companyname" becomes the property of visualforce page, we can get any values that stored inside the Companyname variable.

In apex Controller

We should declare the getter and setter property in following way

1. public String myCompany {get; set;}

2. public String getmyCompany()
{
   return "Everything is works";
}

public String setmyCompany(String s)
{
 return s;
}


3. public String myCompany;

  public String getmyCompany()
{
 return this.myCompany = "Everthing works fine"
}

public String setmyCompany(String s)
{
return this.myCompany = s;
}


4. public void myactionfunction()
   {
        myCompany = "this is my name";
    }

In Visualforce page

In the visualforce page, we can use the getter and setter property by using {!companyName}

if you need set the value to the property from JavaScript, we can use

we can call any method in Apex Controller through


        
        
 
    
        
 


Comments

Popular posts from this blog

Salesforce DX Learning