Slaesforce FAQ

what are get and set methods in salesforce

by Amelie Becker Published 2 years ago Updated 1 year ago
image

The get and set method are methods contained in an Apex Property https://developer.salesforce.com/docs/atlas.en-us.apexcode.meta/apexcode/apex_classes_properties.htm. The get method is called anytime that the property is read, and the set property is called anytime that the property is set.

The "get" method is used to pass data from your Apex code to your Visualforce page.. In our example we are not passing any value.. hence, when your page loads initially the textbox will have a empty value. Set methods are used to assign a new value to the property.

Full Answer

What is the use of get and set methods in Visualforce?

Without a getter or setter, even public or global variables cannot be referenced in Visualforce expressions. Get methods are used to initialize a property (variable) in a class such that when a visualforce page calls that property - it can display its value on the vf page

What is the use of set method in Salesforce controller?

Set methods are used to assign a new value to the property. The "set" method is used to pass values from your visualforce page to the controller... In our example the variable "userinput" will be storing the value entered in the textbox. Hope this helps you.

What is the purpose of using getter and setter methods in Salesforce?

What is the purpose of using Getter and Setter methods in salesforce? When and how {get; set;} methods are used? Visualforce requires a "getter" and "setter" to reference a variable in the controller or extension. Without a getter or setter, even public or global variables cannot be referenced in Visualforce expressions.

How to use APEX method in Salesforce?

To use an Apex method you need to call or invoke it. For the creation of the method in the Apex Set class, We can create an Apex Set method by following the syntax given below-

image

What is get method in Salesforce?

get method ( ) When visualforce page want to get the value of a variable defined in the Apex. It will invoke get method of that variable. In the above example, Visualforce page is trying to use name variable which is declared in Apex class.

What are the methods of Set in Salesforce?

There are several kinds of methods available in the set class. So, here are the list methods in Salesforce.add(set Element)addAll(SetElement)clear()clone()add(index, setElement)equals(set2)removeAll(setOfElementsToRemove)remove(setElement)More items...•

What is get and post method in Salesforce?

The GET method is meant for data retrieval only and should not have any side-effects. But POST is meant for that specific purpose: altering data on the server side.

What does get Set mean in Apex?

What you are seeing with {get;set;} is an example of automatic properties. From the Apex Documentation on Automatic Properties. Properties do not require additional code in their get or set accessor code blocks. Instead, you can leave get and set accessor code blocks empty to define an automatic property.

Why we use Set in Salesforce?

Set: A set is an unordered collection of primitives or sObjects that do not contain any duplicate elements. So, use set if you want to make sure that your collection should not contain Duplicates.

What is difference between list and Set in Salesforce?

A list is an ordered collection of elements that are distinguished by their indices. List elements can be of any data type—primitive types, collections, sObjects, user-defined types, and built-in Apex types. A set is an unordered collection of elements that do not contain any duplicates.

What is Apex method?

In Apex, all primitive data type arguments, such as Integer or String, are passed into methods by value. This fact means that any changes to the arguments exist only within the scope of the method. When the method returns, the changes to the arguments are lost.

What are REST methods in Salesforce?

Each resource in REST API is identified by a named Uniform Resource Identifier (URI) and is accessed using standard HTTP methods (HEAD, GET, POST, PATCH, DELETE). REST API is based on the usage of resources, their URIs, and the links between them. You use a resource to interact with your Salesforce org.

What is the difference between PUT and POST methods?

The PUT Method The difference between POST and PUT is that PUT requests are idempotent. That is, calling the same PUT request multiple times will always produce the same result. In contrast, calling a POST request repeatedly have side effects of creating the same resource multiple times.

What is property in Salesforce?

An Apex property is similar to a variable. Property definitions include one or two code blocks, representing a get accessor and a set accessor: The code in a get accessor executes when the property is read. The code in a set accessor executes when the property is assigned a new value.

What is a wrapper class in Salesforce?

What is Wrapper Class in Salesforce? A wrapper class is nothing but a collection of different Salesforce data types. In Salesforce, you can combine multiple data types and utilize them for various purposes. For example, there is a wrapper class that can access the account records and displays an in-page block table.

What is view state in Salesforce?

View state holds the state/size of the visual force page that includes the components, field values, and controller state. This is important in the light that salesforce provides only a standard size of 135kb for any individual page.

How to declare a set in Salesforce?

To declare a set, use the Set keyword followed by the primitive data type name within <> characters. Moving ahead, get set methods in Salesforce are generally used together as needed.

Why is a list method important in Apex?

The reason why list methods in apex are so important because the output of the SOQL query is a List. Lists are basically ordered collection of data and frequently used within databases. The objective of this blog is to make you familiar with list methods in Salesforce and get set methods in Salesforce.

addAll (fromList)

Adds all of the elements in the specified list to the set if they are not already present.

addAll (fromSet)

Adds all of the elements in the specified set to the set that calls the method if they are not already present.

containsAll (listToCompare)

Returns true if the set contains all of the elements in the specified list. The list must be of the same type as the set that calls the method.

containsAll (setToCompare)

Returns true if the set contains all of the elements in the specified set. The specified set must be of the same type as the original set that calls the method.

equals (set2)

Compares this set with the specified set and returns true if both sets are equal; otherwise, returns false.

removeAll (listOfElementsToRemove)

Removes the elements in the specified list from the set if they are present.

removeAll (setOfElementsToRemove)

Removes the elements in the specified set from the original set if they are present.

image
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z 1 2 3 4 5 6 7 8 9