Salesforce
Iterview Questions
Anserwer
1.What is the difference between
Trigger.new and Trigger.old and
Trigger.newmap and Trigger.oldmap ?
Trigger.new returns new records and
Trigger.old return data before updates
were done. Trigger.newmap returns
new records with id's and
Trigger.oldmap return data before
updates were done with id's.
2. What is the use of trigger.isexecuting?
Suppose we have a method in apex class
and we want this method to run only
when the method is getting called from
apex trigger than we can make use of
trigger.isexecuting in apex class to check
if the method is getting called from
trigger .
3. Why we cannot pass objects as arguments
in future method? Is it possible to call future
method from Batch class or another future
method?
Object data might change between the
time you call the future method and the
time it actually executes. and hence we
pass record id. No, we cannot call future
method from Batch class or another
future method.
4. If the future method was queued before a
service maintenance what will happen?
It will remains in queue and when maintenance is
over and resources are available it will get execute.
5. Is the id of record changes if we undelete a
deleted record?
No, It has the same id.
6. What is database.stateful interface?
Batch Apex is stateless. Each execution of a batch
Apex job is considered a discrete transaction. If
we implements Database.Stateful we can
maintained state across transactions. Using
Database.Stateful only instance variable holds
values static members does not hold values. If we
want to count records as batch proceeds
maintaining state is important as after one
transaction new transaction will start and
members will loose their values.
Thanks for Reading
Follow for more insights!!