LearnSalesforce

Triggers in Salesforce:

Chapter 1.
Never Ever Give Up
Basics of trigger


Did you google(d) this sentence.....! Okay, hurry here is the answer. Let me start with very basic & practical example -Here  Adam & Harry are having the same discussion

Adam says: In Salesforce, we use the trigger to implement custom business logic with help of code to execute some simple & complex logic. 

Harry says:  GotchU!!! But man Why the only trigger? can't you do this with Workflow or process builder or Salesforce in-built functionality?

Adam says: Buddy, You are correct, Going good but let me recall what you can do with workflow & what extra we need in these-

  1. You can not create a new record with help of Workflow.
  2. Deletion of record is not possible.
  3. Update from parent to child is not possible.Only child to parent record can be updated.
  4. Multiple rules need to write for multiple functionalities. 
Adam says: Still, you are confused why I need Trigger do not worry.I will give example in more details.

Harry says: Adam, I am just worried I will able to learn this new concept or not. :-(

Adam says: NoWorry Dude..! No worry..! I will tell the simplest thing how I started imagination of trigger world. :-)

Adam: Here we go...
Let's take an example, you want to create a record Before inserting a record. I am trying to create a contact when whenever an account is created. Did you get that Harry...?

Harry: A little bit...Can you explain more

Adam: of course! let's take another example. 
1.I want to send an email when high Opportunity is deleted. 
2.Alert me before submitting empty phone number on the registration page.
3. Enter Default welcome in Description field of a new account.
4.More complex like- on a check of same address field billing address should be copied to the permanent address.

Adam: Is it okay...! concept is hitting you OR over the head.

Harry: Yes Yes now looking fine...Please go ahead. I am looking for code how can learn 'Coding'  & DML operations & live example.

Adam: thanks for thumps up.. We can have some 7 events on a trigger.I will walk over Code First & basic syntax of Trigger.

Syntax: 

*****CODE*****
Trigger Trigger_name on Object_name(Event){                   //evensts=/before Insert,BeforeUpdate...
        if(trigger.Context variable)                                            // context variable= IsBefore,IsInsert....
             {
                for(holding list of varible)                                     // variable list = trigger.new,Trigger.old...
              }
              bla....
              bla....
              bla... code here 

}

*****CODE*****

Adam: We will go one by one what  Event, Context variable, variable list  & all.But you have to wait for Harry I am going to a movie now :) We will discuss more in next chapter till then you can think what you can do more with Triggers...Hurreyyy....!!! By

for Chapter 2 Next page....in few days.. Keep Reading









Comments

Post a Comment

Popular posts from this blog

LWC Interview Questions Part-1

Lightning Web Component