Sample Questions and Answers
What is the effect of with sharing on inner classes inside a class declared with sharing?
A) Inner classes do not inherit sharing from outer classes
B) Inner classes always inherit sharing
C) Inner classes ignore sharing rules
D) Inner classes must explicitly declare sharing
Answer: A) Inner classes do not inherit sharing from outer classes
Explanation:
Sharing settings must be declared per class.
How can you test asynchronous Apex like future methods?
A) Use startTest() and Test.stopTest()
B) Run them synchronously by default
C) You cannot test asynchronous Apex
D) Use mock classes only
Answer: A) Use Test.startTest() and Test.stopTest()
Explanation:
This simulates asynchronous method execution in tests.
What is the maximum heap size allowed for synchronous Apex?
A) 6 MB
B) 12 MB
C) 24 MB
D) 36 MB
Answer: B) 12 MB
Explanation:
Synchronous Apex heap size limit is 12 MB.
Which method is NOT part of the Database class?
A) rollback()
B) update()
C) commit()
D) insert()
Answer: C) commit()
Explanation:
Salesforce does not expose a commit() method.
What does Test.isRunningTest() return?
A) True if the code is running in a test context
B) False during test execution
C) True if the test passed
D) None of the above
Answer: A) True if the code is running in a test context
Explanation:
Helps differentiate test context from normal execution.
How do you call an Apex method from a Lightning Web Component?
A) Import the Apex method with @salesforce/apex and call it imperatively or wire
B) Use @AuraEnabled on the component
C) Use RemoteAction annotation
D) Use Visualforce remoting
Answer: A) Import the Apex method with @salesforce/apex and call it imperatively or wire
Explanation:
LWC calls Apex with import and decorators.
What is the default rollback behavior for DML exceptions?
A) The entire transaction rolls back
B) Partial success is allowed
C) No rollback occurs
D) Only the failed record is rolled back
Answer: A) The entire transaction rolls back
Explanation:
DML exceptions roll back the whole transaction unless allOrNone is false.
What is the default access level for an Apex class without any sharing declaration?
A) With sharing
B) Without sharing
C) System mode
D) User mode
Answer: B) Without sharing
Explanation:
Apex classes run without sharing by default unless specified with the with sharing keyword.
Which annotation is used to expose an Apex method to Lightning Components?
A) @AuraEnabled
B) @InvocableMethod
C) @RemoteAction
D) @RestResource
Answer: A) @AuraEnabled
Explanation:
@AuraEnabled exposes Apex methods to Lightning Aura and Lightning Web Components.
How can you query for records related to a parent object in SOQL?
A) Use a relationship query with dot notation, e.g., SELECT Account.Name FROM Contact
B) Use a subquery in the WHERE clause
C) Use aggregate queries
D) Use raw SQL
Answer: A) Use a relationship query with dot notation, e.g., SELECT Account.Name FROM Contact
Explanation:
You use dot notation to access parent fields from a child object.
What is the maximum number of batch Apex jobs that can be queued or active concurrently?
A) 5
B) 10
C) 50
D) 100
Answer: B) 5
Explanation:
The Salesforce limit allows up to 5 queued or active batch jobs per org.
What does the with sharing keyword enforce in Apex classes?
A) Enforces the sharing rules of the current user
B) Bypasses sharing rules
C) Runs the class in system mode
D) Disables field-level security
Answer: A) Enforces the sharing rules of the current user
Explanation:
Classes declared with with sharing enforce sharing rules during record access.
Which Apex method would you use to perform DML operations that allow partial success?
A) insert(records, false)
B) insert records
C) Database.update(records)
D) update records
Answer: A) Database.insert(records, false)
Explanation:
Using allOrNone=false allows partial success on DML operations.
Which feature lets you schedule Apex classes to run at specific times?
A) Schedulable interface
B) Batchable interface
C) Queueable interface
D) Future methods
Answer: A) Schedulable interface
Explanation:
Classes implementing the Schedulable interface can be scheduled.
How do you test a batch Apex class?
A) Instantiate the batch class and call executeBatch() within test methods
B) Call execute() method directly
C) Use Test.isRunningTest()
D) Batch classes cannot be tested
Answer: A) Instantiate the batch class and call Database.executeBatch() within test methods
Explanation:
This simulates running the batch job during tests.
What is a governor limit?
A) A runtime limit Salesforce enforces to ensure efficient resource use
B) A limit on the number of users
C) A restriction on custom objects
D) A rule for data validation
Answer: A) A runtime limit Salesforce enforces to ensure efficient resource use
Explanation:
Governor limits prevent code from monopolizing shared resources.
How can you prevent recursion in Apex triggers?
A) Use static Boolean flags to check if code has run before
B) Use recursive SOQL queries
C) Use process builder instead
D) Do nothing, recursion is prevented by Salesforce automatically
Answer: A) Use static Boolean flags to check if code has run before
Explanation:
Static variables can help track and prevent recursive trigger calls.
Which Apex data structure maintains key-value pairs?
A) Map
B) List
C) Set
D) Queue
Answer: A) Map
Explanation:
Map stores key-value pairs.
How do you call a Queueable Apex job?
A) enqueueJob(new MyQueueableClass())
B) Database.executeBatch()
C) System.schedule()
D) MyQueueableClass.execute()
Answer: A) System.enqueueJob(new MyQueueableClass())
Explanation:
Queueable Apex jobs are enqueued via System.enqueueJob().
What is the benefit of using Custom Metadata Types?
A) They allow you to deploy configuration data between orgs easily
B) They store large files
C) They replace all Apex code
D) They limit sharing rules
Answer: A) They allow you to deploy configuration data between orgs easily
Explanation:
Custom Metadata Types help manage configuration declaratively and migrate it.
Which method is used to add an element to a List in Apex?
A) add()
B) put()
C) insert()
D) append()
Answer: A) add()
Explanation:
List.add() adds elements to a list.
What happens if you perform a DML operation on a large number of records without bulkifying?
A) You risk hitting governor limits and exceptions
B) The operation completes faster
C) Salesforce automatically bulkifies the code
D) There is no impact
Answer: A) You risk hitting governor limits and exceptions
Explanation:
Bulkification prevents hitting limits in batch operations.
How many SOQL queries can be executed in a single synchronous Apex transaction?
A) 100
B) 200
C) 50
D) 500
Answer: A) 100
Explanation:
The limit is 100 queries for synchronous Apex.
Which object does a trigger run in the context of?
A) The user who initiated the DML operation
B) The system user
C) The admin user
D) The last logged-in user
Answer: A) The user who initiated the DML operation
Explanation:
Triggers respect the permissions of the user who triggered them.
What is the purpose of @Future annotation in Apex?
A) To run methods asynchronously in a separate thread
B) To mark test methods
C) To create batch jobs
D) To schedule jobs
Answer: A) To run methods asynchronously in a separate thread
Explanation:
@Future marks methods to run asynchronously.
How do you update records efficiently in Apex?
A) Use bulk DML operations outside loops
B) Update records inside for loops one by one
C) Use dynamic SOQL inside loops
D) Avoid using DML statements
Answer: A) Use bulk DML operations outside loops
Explanation:
Bulk DML reduces resource consumption and limits.
Which statement about Visualforce controllers is true?
A) Controllers can be standard, custom, or extensions
B) Controllers cannot interact with Apex
C) Controllers only work with Lightning Web Components
D) Controllers are deprecated
Answer: A) Controllers can be standard, custom, or extensions
Explanation:
Visualforce uses various types of controllers.
What is a wrapper class in Apex?
A) A class that groups multiple objects or variables into one object
B) A class used for exception handling
C) A standard Salesforce class
D) A Visualforce controller
Answer: A) A class that groups multiple objects or variables into one object
Explanation:
Wrapper classes simplify complex data handling.
Which of the following is true about static variables in Apex?
A) They maintain state throughout the transaction
B) They reset after each SOQL query
C) They cannot be accessed in triggers
D) They are only available in test methods
Answer: A) They maintain state throughout the transaction
Explanation:
Static variables persist during the execution context.
What is the maximum length of a text field in Apex?
A) 255 characters
B) 1000 characters
C) 4000 characters
D) 131,072 characters
Answer: A) 255 characters
Explanation:
Text fields are limited to 255 characters.
Which annotation allows a test method to see private variables?
A) @TestVisible
B) @IsTest
C) @Private
D) @Expose
Answer: A) @TestVisible
Explanation:
@TestVisible exposes private elements to test classes.
How do you handle callouts in Apex test classes?
A) Use HttpCalloutMock and setMock()
B) Make real HTTP calls
C) Ignore callouts in tests
D) Use @future methods
Answer: A) Use HttpCalloutMock and Test.setMock()
Explanation:
Mocks simulate callout responses in tests.
What does the Trigger.old context variable contain?
A) The records before the DML operation
B) The records after the DML operation
C) New records inserted
D) Deleted records only
Answer: A) The records before the DML operation
Explanation:
Trigger.old contains old versions of the records.
How many classes can implement the Schedulable interface per org per 24 hours?
A) 100
B) 50
C) 200
D) 5
Answer: A) 100
Explanation:
The limit is 100 scheduled jobs per org per day.
Which data structure can guarantee unique values only?
A) Set
B) List
C) Map
D) Queue
Answer: A) Set
Explanation:
Sets store unique values without duplicates.
What is the purpose of Test.loadData() method?
A) To load test data from static resources into test classes
B) To create test data dynamically
C) To query data in tests
D) To delete test data
Answer: A) To load test data from static resources into test classes
Explanation:
This method simplifies test data setup.
Reviews
There are no reviews yet.