Monday 29 September 2014

Usage of this keyword in salesforce

This keyword used to represent the current instance of the class.

Example:
  1. public class ThisKeyWordExample
  2. {
  3.     String str  = 'Test Me';
  4.    
  5.     public void strMethod(String str)
  6.     {
  7.         System.debug('--Parameter Value--'+str);
  8.         System.debug('--Current Instance Value--'+this.str);
  9.     }
  10.    
  11. }

The above example has One Instance Variable & One Local Variable or Method parameter with same name(i.e. str).

str = Refers parameter value.
this.str = Refers the current instance variable value.

To execute this class go to Developer Console, paste the below line then click execute.

  1. ThisKeyWordExample thisExample = new ThisKeyWordExample();
  2. thisExample.strMethod('Test You');

Reference: this keyword

2 comments:

Activities: Assign Tasks to a Queue Salesforce Lightning

Salesforce announced to assign Tasks to a Queue beginning from Spring'20 release. How does it work? In Setup, enter Queues in th...