Salesforce Developer Interview Questions (Apex & Lightning)

12 min read 2,364 words

What Salesforce Developer Interviews Test

Salesforce developer interviews test your understanding of salesforce developer interview questions through Apex programming proficiency, SOQL query optimization, Lightning Web Components development, trigger framework implementation, and governor limit awareness. Interviewers probe Apex class design, SOQL relationship queries, LWC lifecycle hooks, trigger best practices with handler classes, and bulkification techniques preventing limit violations.

This guide covers Apex programming fundamentals including classes and triggers, SOQL and SOSL query languages, Lightning Web Components and Aura framework, asynchronous Apex patterns like Future and Batch, and Salesforce security models with sharing rules. Modern Salesforce development emphasizes platform best practices following governor limits, test class coverage requirements exceeding 75%, and declarative-first approaches using Flow before custom code. Explore comprehensive technical preparation at our complete interview guide.

Apex Programming Fundamentals

Q: Explain Apex and how it differs from Java.

Apex is Salesforce’s proprietary object-oriented programming language with syntax similar to Java but runs entirely on-demand on Force.com platform. Key differences:

  • Apex compiles to metadata stored on platform, executed by runtime interpreter
  • Strictly enforced governor limits prevent resource monopolization in multi-tenant environment
  • Built-in database integration with SOQL and DML operations
  • Automatic state management and transaction control

Apex supports classes, interfaces, inheritance, collections, and exception handling. Unlike Java, Apex doesn’t support multiple inheritance, has no file I/O operations, and requires 75% test coverage for production deployment.

Q: What are governor limits and why do they exist?

Governor limits enforce runtime resource constraints preventing any single tenant from monopolizing shared platform resources. Critical limits include:

  • 100 SOQL queries per synchronous transaction (200 for asynchronous)
  • 150 DML statements per transaction
  • 50,000 records total retrieved by SOQL queries
  • 10 MB maximum heap size
  • 10 seconds CPU time limit (60 for asynchronous)

Developers must write bulkified code processing records in collections rather than one-by-one loops. Use Limits class checking current consumption: Limits.getQueries() returns SOQL queries used.

Q: How do you write test classes and why is 75% coverage required?

Test classes use @isTest annotation containing test methods with testMethod keyword or @isTest annotation. Salesforce requires minimum 75% code coverage for production deployment ensuring code quality.

Best practices:

  • Use Test.startTest() and Test.stopTest() resetting governor limits
  • Create test data using @TestSetup methods for reusability
  • Test positive scenarios, negative scenarios, and bulk operations
  • Use System.assert() methods validating expected outcomes
  • Avoid @SeeAllData=true preventing org data dependencies

Example: @isTest static void testAccountCreation() { Test.startTest(); Account acc = new Account(Name='Test'); insert acc; Test.stopTest(); System.assertNotEquals(null, acc.Id); }

Q: What are triggers and what’s the difference between before and after triggers?

Triggers execute Apex code automatically before or after DML events (insert, update, delete, undelete) on records. Before triggers run before records saved to database, used for validation and field modification. After triggers run after database save, used for accessing record IDs and related record operations.

Trigger context variables:

  • Trigger.new: List of new versions of records
  • Trigger.old: List of old versions (update/delete only)
  • Trigger.newMap: Map of IDs to new records
  • Trigger.isBefore, Trigger.isAfter: Boolean context flags

Best practice: One trigger per object using handler class pattern delegating logic to separate classes maintaining code organization and testability.

SOQL and Data Queries

Q: What is SOQL and how does it differ from SQL?

SOQL (Salesforce Object Query Language) retrieves records from Salesforce database with syntax similar to SQL but platform-specific differences. SOQL queries single object and related objects through relationships, uses relationship notation with dots and underscores, and doesn’t support SELECT * requiring explicit field listing.

Example: SELECT Id, Name, (SELECT LastName FROM Contacts) FROM Account WHERE Industry = 'Technology' retrieves accounts with related contacts in single query.

SOQL enforces governor limit of 50,000 records total per transaction. Use SOQL for loops processing large result sets: for(Account a : [SELECT Id FROM Account]) { } processes batches preventing heap limit violations.

Q: How do you optimize SOQL queries to avoid hitting governor limits?

Query optimization techniques prevent limit violations and improve performance. Select only necessary fields rather than all fields reducing data transfer. Use WHERE clauses filtering records at database level before processing. Implement relationship queries fetching parent and child records in single SOQL avoiding multiple queries.

Bulkification moves SOQL outside loops:

  • Bad: for(Id accId : accountIds) { Account a = [SELECT Name FROM Account WHERE Id = :accId]; }
  • Good: Map<Id,Account> accountMap = new Map<Id,Account>([SELECT Name FROM Account WHERE Id IN :accountIds]);

Use indexed fields in WHERE clauses (Id, Name, RecordType, lookup fields) enabling database optimization. Monitor query performance with Query Plan tool in Developer Console identifying slow queries.

Q: What’s the difference between SOQL and SOSL?

SOQL queries single object returning specific field data with precise filtering. SOSL (Salesforce Object Search Language) searches across multiple objects returning record IDs matching search terms. SOSL performs full-text searches across Name, Email, Phone fields efficiently.

Example: FIND {acme*} IN ALL FIELDS RETURNING Account(Id, Name), Contact(Id, Name) searches multiple objects simultaneously.

Use SOQL when knowing object and fields to query with precise criteria. Use SOSL for keyword searches across objects, user-initiated searches, or when search term might exist in multiple objects. SOSL more efficient than multiple SOQL queries for multi-object searches.

Q: Explain relationship queries and when to use parent-to-child versus child-to-parent.

Relationship queries traverse object relationships in SOQL. Child-to-parent uses dot notation accessing parent fields: SELECT Id, Account.Name, Account.Owner.Email FROM Contact traversing up to 5 levels.

Parent-to-child uses subqueries accessing related lists: SELECT Id, Name, (SELECT FirstName, LastName FROM Contacts) FROM Account returning parent with child collection.

Use child-to-parent when querying child records needing parent field values. Use parent-to-child when querying parent records wanting related child records. Relationship queries reduce SOQL query count combining data retrieval preventing governor limit violations from multiple queries.

Lightning Web Components

How do Lightning Web Components differ from Aura Components?

Lightning Web Components (LWC) use modern web standards (custom elements, Shadow DOM, ES6+) while Aura uses proprietary framework. LWC provides better performance through browser-native features, smaller bundle sizes, and faster rendering. LWC syntax follows standard JavaScript and HTML whereas Aura requires framework-specific syntax.

LWC components are lightweight reusable building blocks using decorators @api, @track, @wire for reactivity. Aura components use attribute definitions and event-driven architecture. Both frameworks coexist in same application with interoperability support allowing gradual migration from Aura to LWC.

What are LWC decorators and lifecycle hooks?

Decorators provide component metadata. @api exposes public properties/methods to parent components. @track makes private properties reactive (deprecated in favor of default reactivity). @wire connects components to Salesforce data and Apex methods declaratively.

Lifecycle hooks manage component stages:

  • constructor(): Component creation, no DOM access
  • connectedCallback(): Component inserted into DOM
  • renderedCallback(): After render and re-render, use cautiously avoiding infinite loops
  • disconnectedCallback(): Component removed from DOM, cleanup listeners
  • errorCallback(): Error handling from child components

How do you call Apex methods from Lightning Web Components?

Two approaches exist: wire service for automatic reactive data, imperative calls for explicit control. Wire service: @wire(getAccounts) accounts; automatically invokes Apex method reactively updating on parameter changes. Imperative: getAccounts().then(result => { }).catch(error => { }); provides explicit control with promise handling.

Apex methods require @AuraEnabled annotation exposing to Lightning components. Add cacheable=true for read-only methods improving performance through client caching: @AuraEnabled(cacheable=true) public static List<Account> getAccounts(). Use imperative calls for DML operations, wire service for queries and readonly operations.

Asynchronous Apex and Integration

Q: What are the different types of asynchronous Apex and when to use each?

Asynchronous Apex executes code outside synchronous transaction with higher governor limits. Types include:

  • Future Methods: @future annotation for simple async operations and HTTP callouts. Cannot chain future calls or pass sObjects as parameters
  • Queueable Apex: Implements Queueable interface allowing job chaining and sObject parameters. Returns job ID for monitoring
  • Batch Apex: Implements Database.Batchable processing up to 50 million records in chunks. Use for data migrations and bulk operations
  • Scheduled Apex: Implements Schedulable interface running code at specified times like cron jobs

Use Future for quick async tasks, Queueable for job chaining, Batch for large data volumes, Scheduled for recurring processes.

Q: How do you make HTTP callouts from Apex?

HTTP callouts use HttpRequest and HttpResponse classes communicating with external REST APIs. Must occur in asynchronous context (future/queueable) when triggered by DML operations.

Example:

  • Create request: HttpRequest req = new HttpRequest(); req.setEndpoint('https://api.example.com'); req.setMethod('GET');
  • Send request: Http http = new Http(); HttpResponse res = http.send(req);
  • Process response: if(res.getStatusCode() == 200) { String body = res.getBody(); }

Use Named Credentials storing endpoint and authentication securely avoiding hardcoded credentials. Whitelist remote site in Remote Site Settings before callouts. Handle timeouts and errors gracefully with try-catch blocks.

Q: Explain the difference between with sharing and without sharing.

with sharing enforces user’s record-level sharing rules (OWD, sharing rules, role hierarchy) when querying data. without sharing ignores sharing rules running in system context seeing all records regardless of user access.

Default behavior depends on execution context. Classes without explicit declaration inherit from caller. Triggers run in system mode (without sharing by default) unless explicitly declared.

Best practice: Use with sharing for user-initiated operations respecting security. Use without sharing only when business logic requires seeing all records like batch jobs or integration. Always document security decisions in code comments.

Q: What is dynamic Apex and when should you use it?

Dynamic Apex accesses sObjects and fields at runtime rather than compile time using Schema describes and reflection. Enables flexible code adapting to metadata changes without recompilation.

Use cases:

  • Dynamic SOQL: String query = 'SELECT Id FROM ' + objectName; List<sObject> records = Database.query(query);
  • Field access: sObject obj = ...; Object value = obj.get('FieldName__c');
  • Schema describes: Schema.getGlobalDescribe() retrieving all object metadata

Caution: Sanitize user input preventing SOQL injection using String.escapeSingleQuotes(). Prefer static references when object/field known at compile time for type safety and performance.

Salesforce Platform Practice

20 Practice Questions

1. Maximum SOQL queries in synchronous transaction?

  • 50
  • 100
  • 150
  • 200

2. Minimum test coverage required for production deployment?

  • 50%
  • 75%
  • 80%
  • 90%

3. In code for(Account a : [SELECT Id FROM Account]) {}, what technique prevents heap limit?

  • Batch processing
  • SOQL for loop
  • Future method
  • Queueable apex

4. Before triggers are used for?

  • Accessing record IDs
  • Validation and field modification before save
  • Related record operations
  • Sending emails

5. @AuraEnabled annotation is required for?

  • All Apex methods
  • Apex methods called from Lightning components
  • Trigger handlers
  • Test methods

6. SOSL searches across?

  • Single object only
  • Multiple objects simultaneously
  • Related objects only
  • Custom objects only

7. Governor limit for total records retrieved by SOQL?

  • 10,000
  • 50,000
  • 100,000
  • Unlimited

8. LWC @wire decorator is used for?

  • Event handling
  • Reactive data binding to Apex/adapters
  • Styling components
  • Navigation

9. with sharing enforces?

  • System mode access
  • User’s record-level sharing rules
  • Field-level security
  • Object permissions

10. Maximum CPU time limit in synchronous transaction?

  • 5 seconds
  • 10 seconds
  • 30 seconds
  • 60 seconds

11. Relationship query SELECT Id, Account.Name FROM Contact is?

  • Parent-to-child
  • Child-to-parent
  • Self-relationship
  • Many-to-many

12. Test.startTest() and Test.stopTest() do what?

  • Create test data
  • Reset governor limits
  • Run async code synchronously
  • Both B and C

13. Future methods require?

  • Return values
  • Static and void signature
  • sObject parameters
  • Callout=false

14. Maximum heap size in synchronous transaction?

  • 6 MB
  • 10 MB (was 6 MB, updated)
  • 12 MB
  • 20 MB

15. LWC lifecycle hook for DOM access?

  • constructor()
  • connectedCallback()
  • render()
  • disconnectedCallback()

16. Batch Apex can process up to?

  • 10,000 records
  • 50 million records
  • 100,000 records
  • Unlimited

17. Database.query() is used for?

  • Static SOQL only
  • Dynamic SOQL queries
  • DML operations
  • Callouts

18. Trigger context variable Trigger.new contains?

  • Old record versions
  • New record versions
  • Deleted records
  • Record IDs only

19. Maximum DML statements per transaction?

  • 100
  • 150
  • 200
  • 250

20. cacheable=true in @AuraEnabled is for?

  • DML operations
  • Read-only methods improving performance
  • All Apex methods
  • Test methods

❓ FAQ

⚡ How do I prepare for Salesforce developer interviews with no prior experience?

Complete Salesforce Trailhead modules covering Apex fundamentals, SOQL basics, and Lightning Web Components essentials earning badges demonstrating platform knowledge. Build sample applications in free Developer Edition org practicing triggers, test classes, and LWC components. Focus on governor limits understanding multi-tenancy constraints unique to Salesforce. Many developers transition from Java or C# backgrounds leveraging similar syntax while learning platform-specific patterns.

🔧 What’s more important to study: Apex or Lightning components?

Both matter but emphasis depends on role focus. Backend-heavy positions prioritize Apex programming, trigger frameworks, and batch processing. Full-stack roles require balanced knowledge of Apex for business logic and Lightning components for UI development. Review job description carefully noting whether role emphasizes integration, data migration, or user interface customization adjusting preparation accordingly.

📊 How deep should I understand governor limits for interviews?

Know major limits by heart including 100 SOQL queries, 150 DML statements, 50,000 total records, and 10 MB heap size. More importantly, understand bulkification patterns preventing limit violations through collection-based processing rather than record-by-record loops. Interviewers test practical application asking how you’d refactor code hitting limits demonstrating problem-solving ability beyond memorization.

💡 Should I focus on declarative tools or custom code for interviews?

Salesforce best practice follows declarative-first approach using Flow, Process Builder, or Validation Rules before writing Apex code. Developer interviews still emphasize Apex and Lightning proficiency since custom code handles complex requirements declarative tools cannot. Demonstrate understanding when declarative suffices versus when code becomes necessary showing platform expertise and cost-effective solution design.

🎯 What certifications help Salesforce developer interviews?

Platform Developer I certification validates Apex, Visualforce, and Lightning fundamentals providing structured learning path and recognized credential. Platform Developer II tests advanced topics including integration patterns and complex trigger scenarios. JavaScript Developer I certification demonstrates LWC proficiency. Certifications strengthen resume but hands-on project experience building actual applications often matters more during technical discussions demonstrating practical problem-solving ability.

Final Thoughts

Success with salesforce developer interview questions requires combining platform-specific knowledge with software engineering fundamentals demonstrating both Apex programming proficiency and Lightning component development skills. Focus on understanding governor limits driving bulkification patterns, writing comprehensive test classes exceeding 75% coverage requirements, and implementing trigger frameworks separating concerns through handler classes. Build practical projects showcasing SOQL query optimization, asynchronous processing patterns, and Lightning Web Components lifecycle management.

Companies value Salesforce developers who follow platform best practices balancing declarative and programmatic approaches, understand security models implementing sharing rules appropriately, and write maintainable code following single-trigger-per-object patterns. Your preparation should include mastering Apex fundamentals with collection-based processing, SOQL relationship queries preventing multiple database calls, Lightning component communication through events and wire services, and asynchronous patterns handling large data volumes demonstrating comprehensive platform expertise across backend logic and frontend experiences.

⚠️ Disclaimer: The interview strategies, sample answers, and negotiation tips provided in this guide are for educational purposes only. Hiring decisions are subjective and vary by company and industry. While these strategies are based on professional HR standards, they do not guarantee a specific job offer or result.