PD1 Apex Programming 4 — Questions and Answers
Question 1: What is the correct order of trigger events for an update operation?
- before insert, after insert
- before update, after update (Correct answer)
- before delete, after delete
- before undelete, after undelete
Correct answer: before update, after update
An update DML operation fires the before update event first (for validation/modification), then after update (for downstream logic).
Question 2: Which method on the Limits class returns the number of SOQL queries issued so far in the current transaction?
- Limits.getSoqlQueries()
- Limits.getQueries() (Correct answer)
- Limits.getQueryRows()
- Limits.getDmlStatements()
Correct answer: Limits.getQueries()
Limits.getQueries() returns the number of SOQL queries consumed so far in the current Apex transaction.
Question 3: What is the behavior of `Database.insert(records, false)` compared to `insert records`?
- It inserts records without firing triggers
- It allows partial success, inserting valid records and collecting errors for failed ones (Correct answer)
- It bypasses validation rules
- It performs an upsert operation instead
Correct answer: It allows partial success, inserting valid records and collecting errors for failed ones
Passing false as the second argument enables partial processing: successful records are committed and failures are captured in SaveResult objects.
Question 4: Which Apex class is used to invoke a named credential-based callout?
- Http
- HttpRequest (Correct answer)
- System.Callout
- WebServiceCallout
Correct answer: HttpRequest
HttpRequest is configured with the endpoint (including the callout:namedCredential syntax) and sent via the Http class.
Question 5: What does the `transient` keyword do in an Apex class used with a Visualforce page?
- Marks a variable as read-only
- Excludes a variable from the view state (Correct answer)
- Makes a variable globally accessible
- Forces a variable to be serialized first
Correct answer: Excludes a variable from the view state
The `transient` keyword prevents a variable from being stored in the Visualforce view state, reducing its size.
Question 6: In Apex, which method is used to schedule a class that implements the Schedulable interface?
- System.schedule() (Correct answer)
- System.scheduleBatch()
- Schedulable.execute()
- Database.executeBatch()
Correct answer: System.schedule()
System.schedule() takes a job name, a cron expression, and an instance of the Schedulable class to create a scheduled job.
Question 7: Which trigger context variable contains only the records that have had a field value changed during an update trigger?
- Trigger.new
- Trigger.old
- Trigger.newMap
- There is no automatic filtered variable; you must compare Trigger.new and Trigger.old manually (Correct answer)
Correct answer: There is no automatic filtered variable; you must compare Trigger.new and Trigger.old manually
Apex does not provide a pre-filtered variable; developers must iterate Trigger.new and compare field values with Trigger.oldMap to find changed records.
What is the correct order of trigger events for an update operation?