Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
22 views8 pages

Trigger Questions 1

The document provides a comprehensive overview of workflows and triggers in a programming context, detailing their definitions, differences, and operational mechanics. It covers trigger events, context variables, and best practices for writing triggers, including handling recursive triggers and invoking batch processes. Additionally, it addresses specific scenarios such as data loading and user-specific trigger disabling.

Uploaded by

shubham.hande066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views8 pages

Trigger Questions 1

The document provides a comprehensive overview of workflows and triggers in a programming context, detailing their definitions, differences, and operational mechanics. It covers trigger events, context variables, and best practices for writing triggers, including handling recursive triggers and invoking batch processes. Additionally, it addresses specific scenarios such as data loading and user-specific trigger disabling.

Uploaded by

shubham.hande066
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

QUESTIONS AND ANSWERS

Triggers

========

1.what is an workflow?

Ans:- Workflow Rules are automated process to send E-mails alerts,

assign tasks, update fields on trigger criteria based requirements.

2.When will the Workflows invoke?

Ans- Workflows are invoked

when ever the given W/F criteria is met during the DML operations(Insert (or) update) on
particular object

3. What is a trigger?

Ans:- Triggers are the automated actions when ever any DML operation is performed on
particular object

4.what are the differences between Workflow and triggers?4

Ans:-

Triggers Workflows
1. You can perform all DML operatios 1. You can perform only update operation,
you cannot perform insert ,

(insert,update,delete,undelete) delete and undelete operations

2. You can perform any logic on any 2.You can perform update operation on

object in entire organization only that particular object and


corresponding child object

5.what are the Triggers Events?

Ans:- There are seven trigger events ,this events will specify when the trigger has to be fired

1.Before insert

2.Before update

3.Before delete

4.After insert

5.After update

6.After delete

7.After undelete

6. What are the Trigger Context varibles?

Ans:- These are the varibles where the data will stored in triggers

1.Trigger.New

2.Trigger.Old

3.Trigger.NewMap

4.Trigger.OldMap

5.Trigger.isBefore
6.Trigger.isAfter

7.Trigger.isInsert

8.Trigger.isUpdate

9.Trigger.isdelete

10.Trigger.isundelete

7.If we insert 100 records how many times will Trigger fire?

Ans:- The Trigger will fire only once but the logic written in the trigger will run 100 times (i.e,
on each record once)

8.what is bulk Trigger?

Ans:- All triggers are bulk triggers by default, and can process multiple records at a time.

You should always plan on processing more than one record at a time.

An Event object that is defined as recurring is not processed in bulk for insert, delete, or
update triggers.

9.what is the difference between Trigger.New and Trigger.Old in update Triggers?

Ans:- Before Update

Trigger.New:- It contais the records which you are going to update with the modified values

We can perform Read and Write operation

Trigger.Old:- It contais the recors which you are going to modify with their old values

we can perform read and SOQL

After Update
Trigger.New:- It contais the records which you are going to update with the modified values

We can perform Read ,SOQL and DML

Trigger.Old:- It contais the recors which you are going to modify with their old values

we can perform only read operation

10.what is the difference between Trigger.New and Trigger.NewMap in update Triggers?

Ans:- Trigger.New:-It contais the records which you are going to update with the modified
values

Trigger.NewMap:-It contais Map<Id,Sobject> where "ID" of the records as key and records
as "VALUE";

11.when you can perform operation using Before Trigger and After Trigger which one you
prefer?

Ans:- Before Trigger.

Because if we want to perform any modifications on dats in after Trigger we have to perform
DML operations on data

where as in Before trigger we can perform write operation on data(Bcz data is not yet stored)
which will not considere as DML .

12.Can we write SOQL query to fetch the data in Trigger.New in BeforeTrigger?

Ans:- NO, we cannot write SOQL query on Trigger.New in Before Triggers because the data is
not yet saved to Sobject.
F4c1

NOTE:-we will write SOQL queries to fetch the data was stored in Sobject.

13.Can we write DML on List of records which are in Trigger.New in BeforeTrigger?

Ans:- NO, we cannot write DML operations on records which are Trigger.New because the
data is not yet saved to Sobject.

NOTE:-we can only write DML operations on those records which were saved in Sobject.

14.what are Resursive triggers?

Ans:-If any trigger calls itself then such triggers are called Recursive Triggers.

15. How to handle Recursive triggers?

Ans:- We can handle these recursive Triggers using "Static Boolean".

Example:

public class TriggerHandler{

public Static Boolean flag=true;

public Static void show(){

if(flag==true){

flag=false;

Account a = new Account(Name='sameer');


insert a;

16.How many Triggers we can write on same object with same Trigger event ?

Ans:-yes

17.What is the order of execution of triggers?

Ans:- There is no order of execution of Triggers we cant say which will fire in which sequence.

18.Will field update on the workflow calls the Upadte Trigger?4

Ans:-Yes on the WorkFlow update the Brfore And After Update Triggers will fire.

19.Can we call batchApex from Trigger?

Ans:-Yes you can,

In your Trigger code something like below :-

// BatchClass is the name of batchclass

BatchClass bh = new BatchClass();


Database.executeBacth(bh);

My only concern is that the Trigger would fire on the DML events and that would invoke the
Batch.

20.Can we call schedule apex from Trigger?

Ans:-yes we can call

21.Can we call future methods from Triggers?

Ans:-yes we can call future methods from Triggers,future methods are used in Triggers to avoid
mixed DML exception

22.Can we send Emails using Triggers?

Ans:-Yes we can send Emails using Apex Triggers.

23.What are the good Pratices that you have to mantain while writing Triggers?

Ans:- 1.It has to obey all the Governing Limits

2.While invoking Batch Apex we should see that not more than 5 batch jobs are invoked.

3.we should not write SOQL queries within a loop

4.we should not write DML operations within a Loop

5.At max try to write only one Trigger per Object .(By number of trigger within the
Trigger by using if conditions)
24.How to disable the trigger for a Particular User?

Ans:- By using the CustomSettings (Hirearchy)

25.Are the Triggers are fired while loading the data using DataLoader?

Ans:- yes Triggers will fire while loading the data from Data loader (Dpends on how many
batchs in data loader while loading data).

26.How run the Triggers only when data comes from External System?

Ans:-

You might also like