August 29, 2012

When to use triggers in Salesforce

Triggers are used to perform immediate actions based on the previous action.

If declarative workflows or Process Builders don’t meet your specific needs, then it’s time to turn to a programmatic approach using Apex,’s procedural language. Apex, very similar to Java, is akin to the procedural languages most database systems have to build stored procedures, database triggers, and unit tests that implement reliable, database-centralized, complex business logic. Here’s a quick look at some examples of how you can use Apex with

Example: field update.

     A trigger is Apex code that executes before or after specific Data Manipulation Language (DML) events occur, such as before object records are inserted into the database, or after records have been deleted.


trigger triggerName on ObjectName (trigger_events)

where trigger_events can be a comma-separated list of one or more of the following events:
  1. before insert
  2. before update
  3. before delete
  4. after insert
  5. after update
  6. after delete
  7. after undelete

No comments:

Post a Comment