In brief Trigger.isExecuting determines if the context is
trigger or Visualforce. If it returns true context is trigger otherwise context
is Visualforce or other. In your case Trigger.isExecuting will return true.
Apex Class- public class TriggerContextDemo
- {
- public Boolean updateContact(Contact[] conList)
- {
- // Will not update contact if method is called in TriggerContext
- if(Trigger.isExecuting)
- {
- // Do Not Update Any contact
- System.debug(' $ $ NOT updating contacts');
- }
- else
- {
- // update contacts
- System.debug(' $ $ updating contacts');
- }
- System.debug(' $ $ return ' + Trigger.isExecuting);
- return Trigger.isExecuting;
- }
- }
Apex Trigger on Contact object
- trigger ContextCheckTrigger on Contact (before insert, before update)
- {
- TriggerContextDemo demo = new TriggerContextDemo();
- demo.updateContact(Trigger.New);
- }
$ $ NOT updating contacts // Because Trigger.isExecuting is true
$ $ return true // Trigger Context exist
If we call the same class from Developer console's execute Anonymous like this:
TriggerContextDemo cc = new TriggerContextDemo();
cc.updateContact(null);
In this case same class will result in system.debugs:
$ $ updating contacts
$ $ return false // No trigger context
Thanks to StackExchange Community
Hi Guys, I have all latest dumps of salesforce certification (Summer ‘17) if anyone wants you can mail me at
ReplyDeletesfdcconsultant25@gmail.com
These are original questions from the certification exam and very useful to pass the exam.
Above 90% questions come from it
I have all latest dumps of following exams
Salesforce Administrator (ADM 201)
Salesforce Sales Cloud Consultant (CON 201)
Salesforce Service Cloud Consultant
Platform Developer I
App Builder and App builder transition exam
Good Day!
Bangladesh Primary Education Board PSC Result 2019 With Marksheet
ReplyDelete