Trigger in Salesforce

What is Trigger?

Trigger is a piece of code which executed when before and after event occur.Triggers can be Defined for Standard object(Account,Contact) ,Custom object and some Standard child object .

Apex Trigger is the Apex code which is executed when before or after this Operations performed:

  • insert
  • update
  • merge
  • upsert
  • undelete
  • delete

 

 

Trigger Syntax:

Trigger syntax starts with trigger keyword. After that you use trigger name on object(object name which you want) and conditions under which is fired .Trigger syntax-

 

Trigger Context Variable

All triggers define implicit variables that allow developers to access runtime context.These variables are contained in the System.

isExecuting:

Returns true if current context is Trigger,not a Web service,Visualforce page.

isInsert:

Returns true if Trigger was fired due to insert operations from the Salesforce interface user,Apex or API.

isUpdate:

Returns true if Trigger was fired due to Update operation from the Salesforce Interface User,Apex,API.

isDelete:

Returns true if trigger was fired due to Delete Operation from the Salesforce User Interface,Apex,API.

isAfter:

Returns true if trigger was fired before any records saved.

isbefore:

Returns true if trigger was fired after all records were saved.

isUndelete:

Returns true if trigger was fired after a record is recovered from the Recycle bin.

new:

Its return the list of recently added records in Trigger.

old:

Its return the list of old versions of records in Trigger.

Leave a comment

Design a site like this with WordPress.com
Get started