Sunday , February 25 2018
Home / Apex / Apex Programming for beginners / Apex Trigger / Your first Salesforce Apex Trigger from scratch!!!

Your first Salesforce Apex Trigger from scratch!!!

Writing your first Salesforce Apex Trigger from scratch!!!

Before we dive deep into the abyss of Salesforce Trigger, we should know a little more about Triggers and why do we need a Trigger.

Triggers are set of code lines which are scheduled to run on a DML event, i. e. when a record is created, updated, deleted, merged or recovered and automate the flow of execution before or after the DML event.

But we have another tool to automate business logic on DML event and that is Workflows. As we know that there are certain scenarios, in which we are not able to use Workflow for e.g., If we want to create a record of the separate object, on an update of standard contact object then we simply cannot use workflow. With workflow we can only perform few task i.e., field update, send email, send an outbound message and create a task.

Apex Trigger Schematics

To overcome these limitations of workflow, Salesforce provided us with Trigger. The trigger is the core of Apex when it comes to automating business logic on any DML event.

There are two places where you can write Trigger:

  1. Sandbox
  2. Developer Edition

To upload Triggers on production, we need to make sure that it passes the Salesforce quality check, and should have enough code coverage to be eligible for deployment (at least 1% Trigger’s code coverage and overall production code coverage to be 75% and above).

Once we meet these criteria we can deploy our Trigger to production. There are a couple of ways to write Trigger in Salesforce:

  1. You can go to object definition page and there you can create a trigger specific to an object (this method provides pre defined text to the trigger which helps in writing the code)
  2. Setup >> Customize >> Users >> Triggers >> New
  3. Open developer console, click on new and select apex and then select Apex Trigger.

Next, we will begin with the syntax of the Apex Trigger

Next Post: 

find interview Questions on Trigger here

Interview Questions Apex Trigger

About Sumit Datta

Sumit Datta
I am a 3x Certified Salesforce developer with overall 5 years of IT experience and 3 years of Implementation experience in Salesforce. I am here to share my knowledge and help Beginners in Salesforce to understand the concepts of Apex, Visualforce, Salesforce Lightning and Salesforce Configuration.

Check Also

Salesforce Lightning Interview Questions

Top 50 Salesforce Lightning Interview Questions 2018

Salesforce Lightning Interview Questions Below is the comprehensive list of questions asked in Salesforce Lightning …

Trailhead Leaderboard (Unofficial)

Trailhead Leaderboard(Unofficial)

Trailhead Leaderboard (Unofficial) Hello everyone, Today I am presenting to you Salesforce Trailhead LeaderBoard(Unofficial), a …

Salesforce Trailhead Widget for your Website

Salesforce Trailhead widget for your Website Hi Friends Recently, I have been working on a small …

Salesforce Lightning tutorials

Salesforce Lightning Tutorial: Lightning Component basics

Salesforce Lightning Tutorial: Lightning Component basics Chapter 1: Prerequisite for Lightning Component Development My Domain …

Leave a Reply

Your email address will not be published. Required fields are marked *