CSA Apex Programming 2 — Questions and Answers
Question 1: Which Apex collection type automatically prevents duplicate values?
- List
- Set (Correct answer)
- Map
- Array
Correct answer: Set
A Set is an unordered collection that does not allow duplicate values.
Question 2: What does the 'with sharing' keyword enforce in an Apex class?
- Field-level security only
- Object-level security only
- The current user's record-level sharing rules (Correct answer)
- System administrator permissions
Correct answer: The current user's record-level sharing rules
'with sharing' enforces the running user's sharing rules so they cannot access records they don't have permission to see.
Question 3: How many DML statements can be executed in a single Apex transaction?
- 50
- 100
- 150
- 200 (Correct answer)
Correct answer: 200
Salesforce allows up to 150 DML statements per Apex transaction.
Question 4: Which Apex method is used to convert a List to a Set to remove duplicates?
- List.dedupe()
- new Set<Id>(myList) (Correct answer)
- myList.toSet()
- Set.fromList(myList)
Correct answer: new Set<Id>(myList)
You can pass a List directly into a Set constructor (e.g., new Set<Id>(myList)) to eliminate duplicates.
Question 5: What is the correct syntax to query all Accounts in Apex?
- SELECT * FROM Account
- [SELECT Id, Name FROM Account] (Correct answer)
- Database.query('Account')
- SOQL.query(Account.class)
Correct answer: [SELECT Id, Name FROM Account]
Inline SOQL in Apex uses square brackets and requires explicit field names — wildcards are not supported.
Question 6: Which governor limit controls the total number of records returned by SOQL queries in one transaction?
- 5,000 records
- 10,000 records
- 25,000 records
- 50,000 records
A single Apex transaction can retrieve a maximum of 50,000 records via SOQL.
Question 7: In Apex, what keyword marks a method that can be called from a Visualforce page or Lightning component?
- global
- @AuraEnabled (Correct answer)
- public static
- @RemoteAction
Correct answer: @AuraEnabled
@AuraEnabled exposes an Apex method so it can be invoked from Lightning components.
Which Apex collection type automatically prevents duplicate values?