Quantcast
Wednesday , December 13 2017
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 4.5 years of IT experience and 2.5 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 and Salesforce Configuration.

Check Also

Dreamforce

Dreamforce Global Gathering 2017, my experience and why one should not miss this event.

Dreamforce Global Gathering 2017, my experience and why one should not miss this event. First …

Salesforce AppBuilder Certification

Salesforce AppBuilder Certification Mock Exam 1

Want to test your preparation for the Salesforce AppBuilder Certification?   Salesforce AppBuilder Certification mock Exam …

Salesforce Platform Developer 1 Certification

Salesforce Platform Developer 1 Certification Mock Exam 2

Want to test your preparation for the Salesforce Platform Developer 1 Certification? Then go through …

Advanced Formula, Salesforce Platform unleashed!!!

Advanced Formulas Introduction to formula fields and Advanced Formulas Formula Field is a powerful capability …

Leave a Reply

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