CSA Apex Programming 3 — Questions and Answers
Question 1: What is a 'bulkified' Apex trigger?
- A trigger that runs only on bulk data loads
- A trigger designed to handle up to 200 records efficiently using collections (Correct answer)
- A trigger with no SOQL inside loops
- A trigger that uses Batch Apex internally
Correct answer: A trigger designed to handle up to 200 records efficiently using collections
A bulkified trigger handles up to 200 records in one execution by operating on collections rather than individual records.
Question 2: Which Apex class is used to schedule code to run at a specific time?
- Batchable
- Queueable
- Schedulable (Correct answer)
- Future
Correct answer: Schedulable
Implementing the Schedulable interface allows an Apex class to be scheduled via System.schedule().
Question 3: What does Trigger.new contain in a before insert trigger?
- The old versions of the records
- The new records with their final database values
- The new records without Id fields yet assigned (Correct answer)
- Both old and new versions of the records
Correct answer: The new records without Id fields yet assigned
In a before insert trigger, Trigger.new contains the new records but Id fields have not yet been assigned by the database.
Question 4: Which exception type is thrown when a DML operation violates a validation rule or required field?
- System.LimitException
- DmlException (Correct answer)
- QueryException
- NullPointerException
Correct answer: DmlException
A DmlException is thrown when a DML operation fails due to validation rules, required fields, or other data integrity issues.
Question 5: In Apex, which method sends an HTTP request and waits for the response?
- Http.send()
- HttpRequest.send()
- new Http().send(request) (Correct answer)
- HttpCallout.execute()
Correct answer: new Http().send(request)
You create an Http object and call send(HttpRequest) on it to make a callout and receive an HttpResponse.
Question 6: What annotation must be added to a test class in Apex?
- @TestClass
- @IsTest (Correct answer)
- @UnitTest
- @TestMethod
Correct answer: @IsTest
@IsTest marks a class as a test class, which excludes it from the org's code size limit.
Question 7: Which Apex feature allows you to run asynchronous code that chains multiple jobs?
- Future methods
- Schedulable
- Queueable Apex (Correct answer)
- Batch Apex
Correct answer: Queueable Apex
Queueable Apex allows chaining of jobs by calling System.enqueueJob() from within a Queueable class.
What is a 'bulkified' Apex trigger?