Sample Questions and Answers
Which Apex method allows you to get the list of selected records when using StandardSetController?
A) getSelected()
B) getRecords()
C) getCurrent()
D) getChecked()
Answer: A
Explanation: getSelected() returns the currently selected records in a list controller.
What is the difference between Custom Controller and Controller Extension?
A) A Custom Controller is a standalone controller; a Controller Extension adds functionality to a standard controller
B) Custom Controllers only work with Lightning
C) Extensions replace the standard controller completely
D) There is no difference
Answer: A
Explanation: Extensions augment standard controllers, while custom controllers are entirely custom code.
What is the correct way to implement pagination with a StandardSetController?
A) Use setPageSize(), next(), and previous() methods
B) Query all records and slice manually in Apex
C) Use JavaScript only for pagination
D) Pagination is not supported in Visualforce
Answer: A
Explanation: StandardSetController provides built-in methods to handle pagination efficiently.
What happens if you call a DML operation inside a for loop?
A) It may cause governor limits to be exceeded, potentially leading to runtime exceptions
B) It improves performance
C) It batches all operations automatically
D) It disables triggers for those records
Answer: A
Explanation: Performing DML inside loops can easily hit Salesforce governor limits.
Which of the following annotations is used to make an Apex property accessible for Visualforce data binding?
A) public or global with getter/setter methods
B) @future
C) @TestVisible
D) @deprecated
Answer: A
Explanation: Properties with public or global access modifiers and get; set; can be bound in Visualforce.
How do you avoid hardcoding IDs in Apex classes?
A) Use Custom Settings or Custom Metadata Types for configurable values
B) Always hardcode them for simplicity
C) Use random strings instead of IDs
D) There is no way to avoid hardcoding IDs
Answer: A
Explanation: Custom Settings and Metadata Types help maintain configurable values without hardcoding.
What does the @TestSetup annotation do in Apex test classes?
A) Defines a method to create test data once for all test methods in the class
B) Marks a test method as deprecated
C) Runs the method asynchronously
D) Automatically validates tests during deployment
Answer: A
Explanation: @TestSetup allows sharing common test data for efficient testing.
How do you expose an Apex class property to Lightning Web Components?
A) Use @AuraEnabled(cacheable=true) on the getter method or property
B) Use @future annotation
C) Properties cannot be accessed by LWC
D) Use @RemoteAction only
Answer: A
Explanation: @AuraEnabled(cacheable=true) allows Lightning Web Components to call Apex efficiently.
What is a PageReference object used for in Apex?
A) To redirect or navigate between Visualforce pages
B) To store SOQL queries
C) To execute batch jobs
D) To hold JSON data
Answer: A
Explanation: PageReference represents a page URL and is used to control navigation.
How do you pass parameters from a Visualforce page to its Apex controller?
A) Use URL parameters accessible via currentPage().getParameters()
B) Use only form input fields
C) Parameters cannot be passed to controllers
D) Use JavaScript only
Answer: A
Explanation: Controllers can read URL parameters via the current page context.
Which Visualforce component allows you to dynamically include another page or component?
A) <apex:include>
B) <apex:insert>
C) <apex:dynamicContent>
D) <apex:embed>
Answer: A
Explanation: <apex:include> inserts the content of another Visualforce page.
How do you prevent SOQL injection in Apex?
A) Use bind variables (:variable) instead of string concatenation for dynamic queries
B) Use string concatenation for queries
C) Avoid using SOQL altogether
D) There is no risk of SOQL injection in Apex
Answer: A
Explanation: Bind variables sanitize input and prevent injection vulnerabilities.
What does the @ReadOnly annotation do in Apex?
A) Allows queries to retrieve up to 1 million records but prohibits DML operations in that context
B) Prevents the class from being edited
C) Makes variables immutable
D) Locks the database record for updates
Answer: A
Explanation: @ReadOnly lets long-running queries retrieve more data but no data modification.
How can you expose an Apex method to JavaScript on a Visualforce page?
A) Use @RemoteAction annotation and call the method via JavaScript remoting
B) Use @AuraEnabled only
C) Use @future annotation
D) JavaScript cannot call Apex methods
Answer: A
Explanation: @RemoteAction enables client-side JavaScript to invoke Apex methods asynchronously.
What happens if you define a method with the same name as the Apex class?
A) It is treated as a constructor
B) It causes a compile-time error
C) It is treated as a static method
D) It is ignored by the compiler
Answer: A
Explanation: Method names matching the class name are constructors in Apex.
What are Queueable Apex jobs used for?
A) To chain jobs with more complex processing than @future methods and allow job monitoring
B) To schedule jobs at specific times
C) To run synchronous code only
D) To automatically retry failed jobs without coding
Answer: A
Explanation: Queueable Apex supports job chaining and monitoring for asynchronous processes.
What is the advantage of using Lightning Data Service over Apex controllers?
A) It simplifies data access by handling caching, sharing, and CRUD operations without Apex
B) It does not support CRUD operations
C) It requires writing more Apex code
D) It cannot be used in Visualforce pages
Answer: A
Explanation: Lightning Data Service reduces Apex code by managing data and caching for you.
What is the best practice when writing test methods for Apex controllers?
A) Create comprehensive test data, cover positive and negative scenarios, and verify results with assertions
B) Write tests only for positive scenarios
C) Avoid using test data and rely on existing org data
D) Do not use assertions in tests
Answer: A
Explanation: Thorough tests ensure reliable, maintainable, and deployable Apex code.
What is the purpose of the with sharing keyword in Apex?
A) To enforce the sharing rules of the current user for the class execution context
B) To override sharing rules completely
C) To prevent sharing rules from being enforced
D) It only applies to test classes
Answer: A
Explanation: with sharing respects user permissions and sharing when querying or manipulating records.
Which Visualforce tag is used to display a list of records with pagination support?
A) <apex:pageBlockTable> combined with StandardSetController pagination
B) <apex:repeat> without pagination
C) <apex:dataTable> only supports static lists
D) <apex:list>
Answer: A
Explanation: pageBlockTable can be used with StandardSetController to display paginated data.
How do you expose Apex properties to Lightning Web Components (LWC)?
A) Properties must have @AuraEnabled annotation and be public static or instance methods with getters
B) Use @RemoteAction only
C) Properties are not accessible from LWC
D) Use @future annotation
Answer: A
Explanation: @AuraEnabled exposes Apex methods and properties to LWC for seamless integration.
Reviews
There are no reviews yet.