APEX VARIABLE • METHODS • OBJECT

Apex Variable, Methods, Object

CLASS VARIABLE :
The variable in the class should specify the following properties when they are defined.

Optional: 
  • Modifiers such as public or final as well as static. 
  • The value of the variable.
  • The name of a variable.
Required: 
  • The data type of the variable, such as String or Boolean.
Syntax :
=================================================
[ public | private | protected | global | final ] [static] data_type variable_name
=================================================

Example :
=================================================
private static final Integer My_INT;
private final Integer i=1;
=================================================

CLASS METHODS : 

To define a method, specify the following.

Optional:
  • Modifiers, such as public or protected.
Required:
  • The data type of the value returned by the method, such as String or Integer. Use void if the method does not return a value.
  • A list of input parameters for the method, separated by commas, each preceded by its data type, and enclosed in parentheses ().If there are no parameters, use a set of empty parentheses.
  • A method can only have 32 input parameters.
  • The body of the method, enclosed in braces { }. 
  • All the code for the method, including any local variable declarations, is contained here.
Syntax:
=================================================
( public | private | protected | global ) [override] [static] data_type method_name (input parameters) 
{
   //The body of the method.
 }
=================================================

Example 1 :
=================================================
public static Integer getInt()
{
  return MY_INT;
}
=================================================

Example 2 :
=================================================
public class Example 
{
  public Integer Show (Integer age)
  {
    System.debug('my age is' +age );
    }
}
=================================================

In the above code, it will accept age value as an Integer type, for example, if the input is 20 then it will accept 20 and display the output as my age is 20.
OBJECT :
  • The object is an instance of the class. This has both state and behaviour.
  • Memory for the data members is allowed only when you create an object.
Syntax:
=================================================
classname objectname = new classname ();
=================================================
  • classname This is the name of class for which we are creating an object.
  • objectname This is a reference variable.
  • new This is a keyword which we are allocating the memory.
  • () This is contructor.
Example:
=================================================
class Example
{
   //your code here
}
Example e = new Example();
=================================================

In this way, you can use apex variable, method, object in salesforce.

WOHOO0 !! YOU HAVE JUST COMPLETED APEX VARIABLE EPISODE
If you like this salesforcekid learning platform please let me know in the Comment section...Also, Share with your salesforce folks wish you 
Happy learning ☁️⚡️ (Learn. Help. Share.)


<<PREVIOUS                                                     NEXT >>

APEX VARIABLE • METHODS • OBJECT APEX VARIABLE • METHODS • OBJECT Reviewed by on Rating: 5

No comments:

HELP !! SHARE !! SUGGEST !!

Powered by Blogger.