AssignTo method in apex (Salesforce)

Author - Kiran Preet

AssignTo method is a getter method in Salesforce. It is used to assign the value of an attribute to a class variable in the associated custom component controller. Getter and Setter methods or a property with get and set values must be defined, if this attribute is to be used.

Here is an example: Visualforce page:

<apex:page controller=”Test" >
<apex:form >
<apex:outputText value="{!var}" id="a"/><br/>    
<apex:commandButton value="Show" action="{!show}" rerender="a">
<apex:param assignTo="{!var}" value="orgn"/>
</apex:commandButton>
</apex:form>
</apex:page>

Apex Controller:

public class Test
{    
public String var {get;set;}
public sample()
{
var = 'org';
}    
public void show()
{
System.debug(var);
}
}

Before Clicking Show button:

2102

Webner Solutions is a Software Development company focused on developing Insurance Agency Management Systems, Learning Management Systems and Salesforce apps. Contact us at dev@webners.com for your Insurance, eLearning and Salesforce applications.

Leave a Reply

Your email address will not be published. Required fields are marked *