Salesforce Apex Coding Scenario-based Interview Questions
Salesforce Apex Coding Scenario-based Interview Questions
scenario-based
interview
questions
www.prominentacademy.in
Answer:
@testSetup is used to insert common test data used across
multiple test methods to avoid code duplication.
apex
@testSetup
static void setupData() {
Account acc = new Account(Name='Test');
insert acc;
}
Scenario
How do you validate that an Opportunity’s amount is
greater than its related Account’s AnnualRevenue?
Logic:
Use before insert or before update trigger on Opportunity
and query related Account.
apex
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Scenario
Logic:
Salesforce enforces a limit of 150 DML statements per
transaction. Exceeding this causes runtime errors.
Solution:
Bulkify your logic by collecting records into a list and
performing a single update or insert.
Common Mistake:
❌ Performing DML inside a loop.
Scenario
How to handle NULL in SOQL WHERE clause?
apex
Common Mistake:
❌ Using = NULL instead of = null in Apex context or using
== directly in SOQL string.
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Scenario
How do you create a roll-up summary for objects with a
Lookup relationship?
Logic:
Use Apex Trigger to calculate totals and update parent.
apex
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Scenario
How do you schedule a class to run every Monday at 9 AM?
Logic:
Use System.schedule() with a CRON expression.
apex
// Schedule
String cronExp = '0 0 9 ? * MON'; // every Monday 9 AM
System.schedule('Weekly Job', cronExp, new MyScheduledJob());
Scenario
Logic:
Use Database.query(String) to execute SOQL from a string.
apex
String query = 'SELECT Id, Name FROM Account WHERE Name LIKE
\'%Test%\'';
List<Account> accList = Database.query(query);
Common Mistake:
❌ Improper escaping of quotes, leading to malformed SOQL.
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Scenario
How do you use aggregate functions like GROUP BY in Apex
SOQL?
Logic:
Use AggregateResult class to capture the results.
apex
List<AggregateResult> groupedResults = [
SELECT AccountId, COUNT(Id) total FROM Contact GROUP BY
AccountId
];
for (AggregateResult ar : groupedResults) {
System.debug('Account: ' + ar.get('AccountId') + ', Total: ' +
ar.get('total'));
}
Common Mistake:
❌ Trying to cast AggregateResult directly into custom objects
or failing to use .get() properly.
Scenario
What are key best practices while writing Batch Apex?
Logic:
Use smaller batch sizes if large data sets.
Avoid SOQL/DML in loops.
Implement all 3 methods (start, execute, finish).
Test thoroughly with Test.startTest() and Test.stopTest().
Common Mistake:
❌ Not testing batch properly or doing DML inside the start()
method.
Your next opportunity is closer than you think. Let’s get you there!
📞 Don’t wait—call us at +91 98604 38743 today
Think your skills are enough?
Think again—these salesforce
questions could cost you your
Salesforce job.
Looking to crack your Salesforce interviews and land
your dream job? 💼 We've got you covered! At
Prominent Academy, we specialize in providing end-to-
end interview preparation that ensures you're not just
ready—but confident! 💪
💡 What We Cover:
✅ Mock Interviews tailored to Salesforce roles
✅ Real-world scenario-based questions for Admin,
Developer, CPQ, and Architect tracks
✅ Guidance on resume building and LinkedIn
optimization
✅ In-depth coverage of Salesforce core concepts,
integrations, and projects
✅ Latest Salesforce certification tips and tricks
✅ Unlimited interview calls with top companies
🎯 Whether you're a fresher or an experienced
professional transitioning to Salesforce, we provide
personalized guidance to help you shine in interviews and
stand out in the competitive market