Top 30 Salesforce CPQ Interview Questions & Answers
Thirty Salesforce CPQ interview questions with answers — quote-to-cash, products, bundles, price rules, product rules, approvals and contracts.
The 30 Salesforce Apex interview questions asked most — collections, SOQL, DML, governor limits, triggers, async Apex and testing — with answers.
Salesforce Apex is the backbone of custom business logic on the Salesforce platform. From automating business processes and integrating external systems to implementing enterprise-grade applications, Apex enables developers to extend Salesforce capabilities beyond declarative tools.
Whether you're building triggers, asynchronous jobs, REST APIs, integrations, or reusable services, a strong understanding of Apex is essential for every Salesforce Developer. As organizations continue adopting complex Salesforce implementations, interviewers increasingly evaluate candidates on scalability, governor limits, security, and best practices.
Modern Apex development goes far beyond writing code. Developers are expected to understand asynchronous processing, bulkification, integrations, design patterns, test automation, and enterprise architecture while adhering to Salesforce's multi-tenant platform limitations.
In this comprehensive guide, we'll explore the Top 30 Salesforce Apex Interview Questions & Answers covering beginner, intermediate, and advanced concepts frequently asked in Salesforce Developer interviews.
Apex is Salesforce's strongly typed, object-oriented programming language used to execute custom business logic on the Salesforce platform.
Apex enables developers to interact with Salesforce data, automate business processes, integrate external systems, and create scalable enterprise applications.
Apex is a proprietary programming language developed by Salesforce that runs on the Lightning Platform and supports custom application development.
| Feature | Description |
|---|---|
| Object-Oriented | Supports Classes and Inheritance |
| Strongly Typed | Variables Require Data Types |
| Database Integrated | Native SOQL & DML Support |
| Multi-Tenant | Runs Within Governor Limits |
| Asynchronous Processing | Supports Batch & Queueable Apex |
| Secure | Respects Salesforce Security Model |
User Action
│
▼
Trigger / Class
│
▼
SOQL Query
│
▼
Business Logic
│
▼
DML Operation
│
▼
Database Update
Salesforce uses a multi-tenant architecture where multiple organizations share the same resources. Governor Limits ensure that no single organization consumes excessive system resources.
| Governor Limit | Value |
|---|---|
| SOQL Queries | 100 Per Transaction |
| DML Statements | 150 Per Transaction |
| CPU Time | 10 Seconds (Sync) |
| Heap Size | 6 MB (Sync) |
| Type | Use Case |
|---|---|
| Future Method | Simple Background Processing |
| Queueable Apex | Complex Async Jobs |
| Batch Apex | Large Data Volumes |
| Scheduled Apex | Time-Based Execution |
| Declarative Tools | Apex |
|---|---|
| Low Code | Custom Code |
| Simple Automation | Complex Logic |
| Limited Flexibility | Highly Flexible |
| Configuration Driven | Code Driven |
| Section | Topics Covered |
|---|---|
| Q1 – Q10 | Apex Fundamentals |
| Q11 – Q20 | Triggers & Asynchronous Apex |
| Q21 – Q30 | Advanced Apex & Architecture |
Part 1: Apex Fundamentals (Q1–Q10)
Part 2: Intermediate Apex (Q11–Q20)
Part 3: Advanced Apex (Q21–Q30)
Salesforce Apex interviews often focus on governor limits, trigger best practices, bulkification, asynchronous processing, security, and integrations. Interviewers usually expect candidates to explain real-world implementations instead of only theoretical concepts.
Let's begin with the most commonly asked Salesforce Apex interview questions covering the foundational concepts every Salesforce Developer should understand.
Apex Basics, Triggers, Governor Limits, SOQL, SOSL, DML Operations, and Exception Handling.
Answer
Apex is Salesforce's strongly typed, object-oriented programming language used to execute custom business logic on the Lightning Platform.
Developers use Apex to automate processes, perform complex calculations, integrate external systems, and build scalable enterprise applications.
Key Features
Example
public class HelloWorld {
public static void sayHello() {
System.debug('Hello Apex!');
}
}
Apex is similar to Java in syntax but is specifically designed for Salesforce's multi-tenant environment.
Answer
Apex is used when declarative tools such as Flows or Validation Rules cannot satisfy complex business requirements.
Common Use Cases
Example Scenario
Requirement:
When Opportunity closes,
automatically create
records in an external ERP.
Solution:
Apex Callout
Apex provides developers with full programmatic control over Salesforce data and processes.
Answer
An Apex Class is a blueprint that contains variables, methods, and business logic.
Classes help organize reusable code and follow object-oriented programming principles.
Example
public class AccountService {
public static void updateRating(Account acc) {
acc.Rating = 'Hot';
}
}
Features of Apex Classes
Answer
Apex Triggers execute custom logic before or after database events occur on Salesforce records.
Trigger Events
Example Trigger
trigger AccountTrigger on Account (before insert) {
for(Account acc : Trigger.new) {
acc.Rating = 'Hot';
}
}
Triggers automate business processes directly during record transactions.
Follow the "One Trigger Per Object" design pattern.
Answer
| Feature | Workflow Rule | Flow | Trigger |
|---|---|---|---|
| Complex Logic | No | Medium | High |
| Code Required | No | No | Yes |
| External Integration | No | Limited | Yes |
| Performance | Medium | Good | High |
| Scalability | Low | Medium | High |
Salesforce recommends using declarative tools first and Apex only when necessary.
Answer
Governor Limits are runtime limits enforced by Salesforce to ensure fair resource usage in its multi-tenant architecture.
Multiple Organizations
Share Same Resources
↓
Prevent Resource Abuse
↓
Governor Limits
Common Limits
Governor Limits are among the most frequently asked topics in Salesforce interviews.
Answer
| Limit Type | Description |
|---|---|
| Per Transaction | Applied to each transaction |
| Static Limits | Fixed Platform Limits |
| Size-Specific | Heap and Query Sizes |
| Lightning Platform | Platform-wide Restrictions |
| Certified Package | Managed Package Limits |
Example
System.debug(
Limits.getQueries()
);
System.debug(
Limits.getLimitQueries()
);
The Limits class helps monitor governor limit consumption during execution.
Answer
| SOQL | SOSL |
|---|---|
| Single Object Search | Multiple Object Search |
| Structured Query | Text Search |
| Uses SELECT | Uses FIND |
| Returns Records | Returns Lists of Lists |
SOQL Example
List<Account> accounts =
[
SELECT Id, Name
FROM Account
];
SOSL Example
List<List<SObject>> results =
[
FIND 'Acme*'
IN ALL FIELDS
RETURNING Account
];
Answer
DML (Data Manipulation Language) operations are used to create, update, delete, and restore Salesforce records.
| DML Operation | Purpose |
|---|---|
| insert | Create Records |
| update | Modify Records |
| delete | Remove Records |
| upsert | Insert or Update |
| undelete | Restore Records |
| merge | Combine Records |
Example
Account acc = new Account(
Name = 'LearnFrenzy'
);
insert acc;
acc.Rating = 'Hot';
update acc;
Answer
Exception Handling allows developers to gracefully handle runtime errors and prevent transaction failures.
Syntax
try {
Account acc = new Account();
insert acc;
}
catch(Exception e) {
System.debug(e.getMessage());
}
finally {
System.debug('Completed');
}
Common Exceptions
Catch specific exceptions instead of using generic Exception whenever possible.
Trigger Context Variables, Bulkification, Future Methods, Queueable Apex, Batch Apex, Integrations, and Test Classes.
Answer
Trigger Context Variables provide information about the current trigger execution and the records involved in the transaction.
Common Context Variables
| Variable | Description |
|---|---|
| Trigger.new | List of new records |
| Trigger.old | List of old records |
| Trigger.newMap | Map of new records |
| Trigger.oldMap | Map of old records |
| Trigger.isInsert | Insert event |
| Trigger.isUpdate | Update event |
| Trigger.isDelete | Delete event |
| Trigger.isBefore | Before event |
| Trigger.isAfter | After event |
Example
trigger AccountTrigger on Account (before update) {
for(Account acc : Trigger.new) {
Account oldAcc = Trigger.oldMap.get(acc.Id);
if(oldAcc.Rating != acc.Rating) {
System.debug( 'Rating changed' );
}
}
}
Answer
Following best practices ensures that triggers remain scalable, maintainable, and governor-limit friendly.
Best Practices
Recommended Architecture
Trigger
│
▼
Handler Class
│
▼
Service Layer
│
▼
Database Layer
Mentioning Trigger Handler Frameworks often creates a positive impression during interviews.
Answer
Bulkification is the process of writing Apex code that can efficiently process multiple records in a single transaction.
Salesforce processes records in batches, so code must handle collections rather than individual records.
Bad Example
for(Account acc : Trigger.new) {
update acc;
}
Good Example
List<Account> updates = new List<Account>();
for(Account acc : Trigger.new) {
acc.Rating = 'Hot';
updates.add(acc);
}
update updates;
Bulkification helps avoid governor limit exceptions.
Answer
Future Methods execute asynchronously in the background after the current transaction completes.
Characteristics
Example
public class FutureExample {
@future(callout=true)
public static void makeCallout() {
// API Callout
}
}
Future methods are commonly used for integrations and long-running processes.
Answer
Queueable Apex provides more flexibility than Future Methods and supports job chaining.
Advantages
Example
public class MyQueueable implements Queueable {
public void execute(QueueableContext qc) {
System.debug('Queueable Job');
}
}
Execute Job
System.enqueueJob(
new MyQueueable()
);
Salesforce recommends Queueable Apex over Future Methods for new development.
Answer
Batch Apex processes large datasets asynchronously by dividing records into manageable chunks.
Batch Lifecycle
start()
│
▼
execute()
│
▼
finish()
Example
global class BatchAccount
implements Database.Batchable<SObject> {
global Database.QueryLocator
start(
Database.BatchableContext bc
) {
return Database.getQueryLocator(
'SELECT Id FROM Account'
);
}
global void execute(
Database.BatchableContext bc,
List<Account> scope
) {
}
global void finish(
Database.BatchableContext bc
) {
}
}
Batch Apex is ideal for processing millions of records.
Answer
Scheduled Apex allows Apex code to run at specific times automatically.
Use Cases
Example
global class MyScheduler
implements Schedulable {
global void execute(
SchedulableContext sc
) {
Database.executeBatch(
new BatchAccount()
);
}
}
Schedule Job
String cron =
'0 0 2 * * ?';
System.schedule(
'Night Job',
cron,
new MyScheduler()
);
Answer
Dynamic SOQL allows queries to be constructed and executed at runtime.
Example
String query =
'SELECT Id, Name
FROM Account';
List<SObject> records =
Database.query(query);
Use Cases
Always prevent SOQL Injection using bind variables.
Answer
Apex supports HTTP callouts to communicate with external systems such as SAP, ERP, and payment gateways.
Callout Flow
Salesforce
│
▼
HTTP Request
│
▼
External API
│
▼
HTTP Response
│
▼
Salesforce
Example
HttpRequest req = new HttpRequest();
req.setEndpoint(
'https://api.example.com'
);
req.setMethod('GET');
Http http = new Http();
HTTPResponse res =
http.send(req);
Named Credentials should be used to securely manage authentication.
Answer
Salesforce requires at least 75% code coverage before deploying Apex to production.
Purpose of Test Classes
Example
@isTest
private class AccountTest {
@isTest
static void testInsert() {
Account acc = new Account( Name='LearnFrenzy');
insert acc;
System.assertNotEquals( null, acc.Id );
}
}
Write meaningful tests that validate behavior rather than only increasing coverage.
Governor Limit Optimization, Security, Managed Sharing, Platform Events, Design Patterns, Enterprise Architecture, and Real-World Apex Scenarios.
Answer
Governor Limit optimization ensures that Apex code executes efficiently within Salesforce's multi-tenant environment.
Optimization Techniques
Bad Example
for(Account acc : accounts) {
update acc;
}
Optimized Example
update accounts;
Most governor limit exceptions occur due to SOQL or DML statements inside loops.
Answer
Apex Managed Sharing allows developers to programmatically share records with users or groups.
It is commonly used when standard sharing rules cannot meet complex business requirements.
Example
AccountShare share =
new AccountShare();
share.AccountId = acc.Id;
share.UserOrGroupId =
userId;
share.AccountAccessLevel =
'Read';
insert share;
Use Cases
Apex Managed Sharing works only when the object's sharing model is not Public Read/Write.
Answer
Apex runs in system mode by default, which means developers must explicitly enforce security.
Security Areas
Example
if(
Schema.sObjectType.Account
.isAccessible()
) {
List<Account> accs =
[SELECT Id, Name
FROM Account];
}
Modern Approach
List<Account> records =
(Security.stripInaccessible(
AccessType.READABLE,
accounts
)).getRecords();
Answer
| Keyword | Description |
|---|---|
| with sharing | Enforces Sharing Rules |
| without sharing | Ignores Sharing Rules |
| inherited sharing | Uses Calling Context |
Example
public with sharing
class AccountService {
}
Using with sharing helps ensure users only access records they are authorized to view.
Prefer inherited sharing in modern Apex development when appropriate.
Answer
Platform Events enable event-driven architectures and asynchronous communication between systems.
Publisher-Subscriber Model
Publisher
│
▼
Platform Event
│
▼
Subscriber
Example
Order_Event__e evt =
new Order_Event__e(
Order_Id__c='1001'
);
Database.SaveResult sr =
EventBus.publish(evt);
Use Cases
Answer
Transaction Control allows developers to commit or roll back changes during execution.
Salesforce provides Savepoints and Rollbacks for transaction management.
Example
Savepoint sp =
Database.setSavepoint();
try {
insert account;
}
catch(Exception e) {
Database.rollback(sp);
}
This ensures data consistency when exceptions occur.
Answer
Design patterns improve code maintainability, scalability, and reusability.
Common Apex Design Patterns
Layered Architecture
Trigger
│
▼
Handler
│
▼
Service
│
▼
Repository
Answer
Enterprise Apex Architecture separates responsibilities into layers to improve maintainability and scalability.
Architecture Layers
| Layer | Responsibility |
|---|---|
| Trigger Layer | Event Handling |
| Service Layer | Business Logic |
| Domain Layer | Object Behavior |
| Repository Layer | Data Access |
| Integration Layer | External APIs |
Architecture Diagram
UI
│
▼
Trigger
│
▼
Service
│
▼
Repository
│
▼
Database
Answer
Consider a Consumer Goods Cloud TPM implementation where promotions need to synchronize with SAP.
Business Requirement
Solution Architecture
Promotion Created
│
▼
Trigger
│
▼
Queueable Apex
│
▼
SAP API Callout
│
▼
Update Status
Key Technologies
Be prepared to explain real projects involving integrations, asynchronous processing, and governor limit optimization.
Answer
A common advanced interview question focuses on designing scalable solutions for processing large data volumes.
Scenario
Requirement:
Process 5 million records
daily and integrate with
external ERP systems.
Proposed Solution
Architecture
Batch Apex
│
▼
Queueable Apex
│
▼
ERP API
│
▼
Platform Events
The goal is to design a scalable, secure, and governor-limit-friendly solution.
Salesforce Apex remains one of the most important skills for Salesforce Developers. Mastering triggers, governor limits, asynchronous processing, security, and integrations enables developers to build scalable enterprise applications on the Salesforce platform.
Hands-on experience with real-world implementations, combined with a strong understanding of Apex best practices and architecture patterns, will significantly improve your success in Salesforce interviews and projects.
In this guide, we covered the Top 30 Salesforce Apex Interview Questions & Answers ranging from foundational concepts to advanced enterprise scenarios. These questions are highly relevant for Salesforce Developers, Technical Leads, Architects, and Platform Developer certification aspirants.
As Salesforce continues to evolve with AI, integrations, and enterprise applications, Apex remains a critical technology for implementing scalable and secure business solutions.
Keep learning, practice real-world scenarios, and continue building enterprise-grade solutions to advance your Salesforce career.
One short email when we publish something new — interview questions, Salesforce guides and career tips. No spam, unsubscribe in one click.
Thirty Salesforce CPQ interview questions with answers — quote-to-cash, products, bundles, price rules, product rules, approvals and contracts.
Salesforce Headless 360 explained — what headless CRM means, how APIs and data cloud power it, and what it changes for developers and businesses.
Apex design patterns explained with code — trigger handler, selector, service, unit of work and factory — for clean, scalable Salesforce code.
Questions, corrections or your own experience — they all help the next reader.