Showing posts with label salesforce tutorials. Show all posts
Showing posts with label salesforce tutorials. Show all posts

Sunday, 9 July 2017

Introduction to Class Variables & Methods and Objects

Introduction to Class Variables & Methods and Objects 

Class variables: 

The variables in the class should specify the following properties when they are defined. 

1.Optional: modifiers such as public or final as well as static. 
2.Required: the data type of the variable, such as string or Boolean. 
3.Optional: the value of the variable 
4.Optional: the name of the variable    

Syntax: 
              [public |private| protected |global| final] [static]
                             Data - type variable – name 
Ex: 
           Private static final integer My-INT; 
           Private finale integer I = 1;

Class methods:

To define a method, specify the following. 
1.optional:  modifiers, such as public or protected.
2.Required:  the data type of the value returned by the method, such as string or integer. Use void if the method does not return value. 
3Required:  A list of input parameters for the method, separated by common, 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. 

4.Required:  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) [over ride] [static]   
            Data-type method- name (input parameters)
         {
         // the body of the method.
          }
Ex1: 
          Public static Integer get Int ()
 {
    return – MY INT ; 
      }
Ex2: 
        Public class example 
        {
          Public Integer Show (Integer age)
         {
           System debug (‘My age is’ tag);
             }
         }

Object:


Object is an instance of the class. This as both state and behavior.
memory for the data members our allocated only when you create an object   

Syntax: 
             Class name object name = New class name ();
                   ↓                   ↓                                            ↓
              Object        variable name                        constructor 

Ex:    
         Class example 
          {
             //code 
            }

          Example e = new example ();

Tuesday, 27 June 2017

Define A Class in Apex

Define A Class in Apex 

Class:

 Class is a collection of data members and methods.
                  Ex:  class student
                         {
                           Integer no;
                           String name;     →                    these are data members of the class
                           Public void gets Details ()
                           {
                             System. Debug (‘roll no’ +no);
                             System. Debug (‘name ‘+name);
                                       }
        }
EX2 :  class employee
          {
            Integer exp ;
            String deportment;
            Void show ()
             {
                //write the logic
               }
           }
   

To define an apex class, specify the following.


a)       Access modifiers:
                                               I.            You must use one of the access modifiers for top level class. (public or global)
                                             II.            You do not have to use access modifiers in the declaration of inner classes.
b)      Optional definition modifiers such as virtual, abstract.
c)       Required: the key word class followed by the class name.
d)      Optional extensions: AND/OR implementation
   
Syntax:
                     Private| public | global [virtual | abstract| with sharing | more]  
                      Class  class name [implements interface Name list|
                     (none)] [extends class name |(none)]
                    {
                           // the body of class

                                                               }