21. What is the difference between
trigger.new and trigger.old in Apex – SFDC?
Ans :
Trigger.new :
Returns a list of the new versions
of the sObject records.
Note that this sObject list is only
available in insert and update triggers, and the records can only
be modified in before
triggers.
Trigger.old :
Returns a list of the old versions
of the sObject records.
Note that this sObject list is only
available in update and delete
triggers.
22. How to restrict any Trigger to
fire only once ?
Ans:
Triggers can fire twice, once before
workflows and once after workflows
“The before and after triggers fire one more
time only if something needs to be updated. If the fields have already been set
to a value, the triggers are not fired again.”
Workaround:
Add a static boolean variable to a
class, and check its value within the affected triggers.
1
2
3
4
5
6
7
8
9
10
11
12
13
|
public class HelperClass
{
public static boolean firstRun
= true;
}
trigger
affectedTrigger on Account (before delete, after delete, after undelete) {
if(Trigger.isBefore){
if(Trigger.isDelete){
if(HelperClass.firstRun){
Trigger.old[0].addError('Before
Account Delete Error');
HelperClass.firstRun=false;
}
}
}
}
|
23. How to create and host S Control
in Salesforce ?
24. Difference between Sandbox and
Development environment?
25. How to schedule export or take
the backup of salesforce?
26. What are the different
Salesforce.com Editions and Limits?
No comments:
Post a Comment
Share your Comments .............