Sample Questions and Answers
What type of exception is thrown when a DML operation violates a validation rule?
A) DmlException
B) NullPointerException
C) QueryException
D) ValidationException
Answer: A
Explanation: Validation rule failures cause DmlException errors.
How do you perform conditional rendering of Visualforce components?
A) Using the rendered attribute with an Apex boolean expression
B) Using JavaScript only
C) Using CSS classes
D) Components cannot be conditionally rendered
Answer: A
Explanation: The rendered attribute conditionally shows components.
What is the role of ApexPages.StandardController in custom controllers?
A) Provides access to standard Salesforce object data in Visualforce
B) Is not used with custom controllers
C) Provides batch processing capabilities
D) Enables Lightning components
Answer: A
Explanation: StandardController wraps standard objects for Visualforce pages.
What Apex method commits changes to the database?
A) DML statements like insert, update, delete
B) Database.commit()
C) System.save()
D) Apex.commit()
Answer: A
Explanation: Apex DML statements save changes to the database.
Which governor limit restricts the number of SOQL queries in a single Apex transaction?
A) 100 synchronous, 200 asynchronous
B) 50 synchronous, 100 asynchronous
C) 150 synchronous, 200 asynchronous
D) Unlimited
Answer: A
Explanation: Limits prevent excessive SOQL queries per transaction.
What happens if a @future method calls a synchronous method that performs a DML operation?
A) The DML is executed asynchronously within the future method
B) An error occurs
C) The synchronous method is blocked
D) The DML is skipped
Answer: A
Explanation: @future methods run asynchronously, so nested DML executes asynchronously.
How do you ensure an Apex trigger runs after a record is inserted or updated?
A) Use after insert or after update event in trigger definition
B) Use before insert only
C) Use before update only
D) Use asynchronous Apex
Answer: A
Explanation: after events occur after DML operations.
What does @InvocableMethod annotation allow in Apex?
A) Method can be called from Flow or Process Builder
B) It marks a test method
C) It marks a future method
D) It runs the method asynchronously
Answer: A
Explanation: Invocable methods can be invoked by declarative automation tools.
Which Visualforce component supports form validation errors display?
A) <apex:pageMessages>
B) <apex:outputText>
C) <apex:inputText>
D) <apex:dataTable>
Answer: A
Explanation: pageMessages shows validation and error messages on the page.
What is the use of the isAccessible() method in Apex schema classes?
A) Checks if a user has read access to a field
B) Enables object creation
C) Deletes records
D) Creates validation rules
Answer: A
Explanation: It verifies user permissions at field level.
Which tool allows deploying Visualforce pages and Apex classes between Salesforce orgs?
A) Salesforce Change Sets
B) Data Loader
C) Workbench
D) Developer Console
Answer: A
Explanation: Change Sets are used to deploy metadata between connected orgs.
How is pagination implemented in Visualforce?
A) Using the StandardSetController class
B) Using JavaScript only
C) By limiting the number of records in SOQL only
D) Pagination is not supported
Answer: A
Explanation: StandardSetController provides pagination functionality.
What is the maximum size of the Visualforce view state?
A) 135 KB
B) 1 MB
C) 100 KB
D) Unlimited
Answer: A
Explanation: Salesforce limits the view state size to 135 KB to optimize performance.
What happens if a Visualforce page doesn’t specify a controller?
A) The page uses the standard controller for the referenced object in the URL
B) The page will fail to load
C) Apex controller is mandatory
D) The page will run in guest mode only
Answer: A
Explanation: Visualforce pages without a custom controller rely on the standard controller.
Which Visualforce component would you use to display a single record detail page with automatic field rendering?
A) <apex:detail>
B) <apex:form>
C) <apex:dataTable>
D) <apex:repeat>
Answer: A
Explanation: <apex:detail> renders the detail page for a single record, respecting layout and permissions.
When should you use a controller extension in Visualforce?
A) When you want to add custom logic to a standard controller without rewriting it
B) When you only use a custom controller
C) To create reusable components
D) To define CSS styles
Answer: A
Explanation: Controller extensions extend standard controller functionality.
What is a characteristic of the Lightning Out feature?
A) Allows embedding Lightning components in Visualforce pages
B) Runs Apex asynchronously
C) Only available in Classic UI
D) Converts Visualforce pages into Lightning pages automatically
Answer: A
Explanation: Lightning Out lets you embed Lightning components into Visualforce or external apps.
What is a trigger context variable in Apex that contains all records being processed?
A) Trigger.new
B) Trigger.old
C) Trigger.isInsert
D) Trigger.size
Answer: A
Explanation: Trigger.new contains the new versions of records in insert or update triggers.
How does Visualforce enforce CRUD and FLS (Field-Level Security) when using a standard controller?
A) It automatically enforces both for standard controller operations
B) You must manually enforce them in Apex
C) It ignores security settings
D) Only enforces CRUD, not FLS
Answer: A
Explanation: Standard controllers respect CRUD and FLS automatically.
What is the purpose of the apex:commandLink component?
A) To create a clickable link that executes an action method
B) To create a file upload button
C) To display read-only text
D) To render images
Answer: A
Explanation: commandLink triggers server-side actions like a button but appears as a link.
What happens if a Visualforce page action method returns null?
A) The same page is re-rendered
B) Redirects to homepage
C) Throws an exception
D) Navigates to an error page
Answer: A
Explanation: Returning null refreshes the current page.
What is a best practice for reducing Visualforce view state size?
A) Mark nonessential variables as transient
B) Use many controller variables
C) Use JavaScript only
D) Store large collections in controller variables
Answer: A
Explanation: transient excludes variables from view state.
Which method is used to bulkify Apex triggers?
A) Process records in collections instead of one at a time
B) Use recursive triggers
C) Query inside loops
D) Perform DML inside loops
Answer: A
Explanation: Bulkification processes many records efficiently in one operation.
What happens when you call Database.insert(records, false) in Apex?
A) Partial insert: successful records commit, failures don’t stop all
B) All or none insert, fails all if any error
C) Inserts synchronously
D) Inserts asynchronously
Answer: A
Explanation: The second argument false enables partial success insert.
Which Apex annotation restricts a method’s visibility to only the current namespace?
A) @AuraEnabled
B) @InvocableMethod
C) @TestVisible
D) @Private
Answer: C
Explanation: @TestVisible exposes private methods/variables for unit testing.
How do you expose an Apex method to Lightning components?
A) Annotate it with @AuraEnabled
B) Use @InvocableMethod
C) Make it public only
D) Use @future
Answer: A
Explanation: @AuraEnabled makes Apex methods callable from Lightning.
Which Visualforce component is required to capture user input in a form?
A) <apex:form>
B) <apex:pageBlock>
C) <apex:sectionHeader>
D) <apex:outputPanel>
Answer: A
Explanation: Forms must be wrapped in <apex:form> for input submission.
How is data passed from Visualforce page to Apex controller?
A) Through bindings between Visualforce components and controller properties
B) Using URL parameters only
C) Through cookies
D) Via HTTP headers
Answer: A
Explanation: Visualforce binds UI components to controller variables.
What is the purpose of ApexPages.addMessage()?
A) To add messages that display on Visualforce pages
B) To send email notifications
C) To log debug messages
D) To write to the database
Answer: A
Explanation: Adds user feedback messages to the page.
What is a feature of the Database.query() method?
A) Executes dynamic SOQL queries at runtime
B) Can only query custom objects
C) Is deprecated
D) Used to perform DML operations
Answer: A
Explanation: Database.query() runs dynamic SOQL strings.
What is a key limitation of the Visualforce <apex:repeat> component compared to <apex:dataTable>?
A) <apex:repeat> does not support built-in sorting or pagination
B) <apex:repeat> supports pagination automatically
C) <apex:repeat> only works for Lists of Integers
D) <apex:repeat> renders HTML comments only
Answer: A
Explanation: <apex:repeat> is a basic iterator without table features.
What is the maximum number of records you can retrieve in a single SOQL query?
A) 50,000
B) 1,000
C) 10,000
D) Unlimited
Answer: A
Explanation: SOQL governor limit is 50,000 records per query.
How can you ensure your Apex code follows the best practices for governor limits?
A) Avoid SOQL or DML inside loops
B) Query all records without limits
C) Use recursive triggers
D) Perform DML operations on each record separately
Answer: A
Explanation: Bulkifying code avoids hitting limits.
Which Visualforce tag allows you to conditionally render sections of a page?
A) rendered attribute on components
B) <apex:condition>
C) <apex:if>
D) <apex:show>
Answer: A
Explanation: The rendered attribute controls whether components are rendered.
How does the with sharing keyword affect Apex classes?
A) Enforces the current user’s sharing rules
B) Allows admin-only access
C) Ignores user permissions
D) Runs code asynchronously
Answer: A
Explanation: with sharing respects sharing rules in Apex.
What is a good way to pass parameters from a Visualforce page to an Apex controller?
A) Use <apex:param> inside command components
B) Use cookies only
C) Hardcode values in Apex
D) Use URL redirects only
Answer: A
Explanation: <apex:param> passes values to controller methods on action.
Which class can be used to batch process large numbers of records asynchronously?
A) Database.Batchable
B) Database.QueryLocator
C) Database.SaveResult
D) ApexScheduler
Answer: A
Explanation: Batch Apex interface supports large-scale data processing.
Which method runs before a record is deleted in Apex triggers?
A) before delete
B) after delete
C) before update
D) after insert
Answer: A
Explanation: before delete runs prior to record deletion.
What Visualforce tag is used to include CSS or JavaScript files?
A) <apex:includeScript> and <apex:stylesheet>
B) <apex:include> only
C) <apex:script> only
D) <apex:link>
Answer: A
Explanation: These tags load external JS and CSS.
What is true about static variables in Apex?
A) Static variables maintain their value throughout a single transaction
B) Static variables store data permanently in database
C) Static variables reset with every method call
D) Static variables are not supported
Answer: A
Explanation: Static variables persist in the transaction context only.
Which method in Apex can prevent recursive triggers?
A) Use a static Boolean flag to limit trigger execution
B) Use asynchronous Apex
C) Remove the trigger
D) Use @future
Answer: A
Explanation: Static flags prevent infinite recursion.
How do you test exceptions in Apex test classes?
A) Use try-catch blocks and System.assert for exception validation
B) Ignore exceptions in tests
C) Use System.debug only
D) Exceptions cannot be tested
Answer: A
Explanation: Testing exceptions ensures robust error handling.
What is the purpose of Test.startTest() and Test.stopTest()?
A) To reset governor limits and test asynchronous code
B) To schedule tests
C) To start and stop Visualforce pages
D) To deploy Apex code
Answer: A
Explanation: These delimiters isolate test execution and simulate async calls.
What does the actionRegion attribute do in <apex:actionRegion>?
A) Limits partial page refresh to specific input components
B) Defines a full page refresh area
C) Disables AJAX
D) Enables file uploads
Answer: A
Explanation: It scopes which inputs are submitted during partial refresh.
Reviews
There are no reviews yet.