Salesforce logo

Salesforce Interview Questions

33 practice questions for Salesforce technical interviews

Salesforce software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer

No verified questions yet for Salesforce.

coding Medium hash map #1

1. Hash Map — Counting occurrences of records

Background: In Salesforce's CRM system, it's crucial to understand the frequency of various record types in customer data analysis and reporting. An effective way to manage large datasets and derive insights requires efficient implementation of counting methods.
Problem statement: Given a list of customer records represented as strings, your task is to create a function that counts how many times each unique record appears in the list. The function should return a dictionary mapping each record to its count. For example: Given the input list ['Lead', 'Contact', 'Lead', 'Opportunity', 'Contact'], the output should be {'Lead': 2, 'Contact': 2, 'Opportunity': 1}.
Function/class signature:
  • def count_records(records: List[str]) -> Dict[str, int]:

Example 1: Input: ['Lead', 'Contact', 'Lead'] → Output: {'Lead': 2, 'Contact': 1} → Explanation: The record 'Lead' appears twice, while 'Contact' appears once.
Example 2: Input: ['Opportunity', 'Client', 'Client', 'Lead'] → Output: {'Opportunity': 1, 'Client': 2, 'Lead': 1} → Explanation: 'Client' appears twice, while both 'Opportunity' and 'Lead' appear once.
Constraints:
  • 1 <= records.length <= 10^5

  • Each record is a non-empty string

coding Medium hash map #2

2. HASH_MAP — Implement a simple inventory system using a hash map


Background: At Salesforce, managing customer inventories efficiently is crucial for CRM solutions. This problem involves storing and processing customer inventories to track items and quantities effectively.
Problem statement: You need to implement a simple inventory system where you can add items to inventory, update the quantities, and retrieve the current count of any item. Your inventory should be based on a hash map for quick access to item counts.
Function/class signature:
  • def add_item(item: str, quantity: int) -> None:

  • def update_item(item: str, quantity: int) -> None:

  • def get_count(item: str) -> int:


Example 1:
  • Input: add_item('Apples', 10)

  • Output: None

  • Explanation: The inventory now has 10 Apples.


Example 2:
  • Input: update_item('Apples', 5) followed by get_count('Apples')

  • Output: 15

  • Explanation: The total count of Apples is updated to 15.


Constraints:
  • The item string will be non-empty and contain at most 100 characters.

  • The quantity will be a positive integer not exceeding 1,000.


coding Medium dynamic programming #3

3. Dynamic Programming — Maximize Revenue from Sales

Background: Salesforce needs to analyze past customer purchase data to optimize sales strategies. This problem relates to their forecasting tools for sales teams.
Problem statement: Given an array of integers representing sales revenue from each day, your task is to calculate the maximum revenue that can be obtained on consecutive days without selling on two consecutive days. The revenue from any day can only be sold once.
Function/class signature:
  • def maximize_revenue(revenue: List[int]) -> int:


Example 1:
Input: revenue = [1, 2, 3, 1]
Output: 4
Explanation: You can sell on days 1 and 3 to get a maximum of 4.
Example 2:
Input: revenue = [2, 7, 9, 3, 1]
Output: 12
Explanation: You can sell on days 2, 4 and get a maximum of 12.
Constraints:
  • The length of the revenue array will be at least 1 and at most 100.

  • Each revenue value will be between 0 and 1000.
coding Medium graph #4

4. Graph — Shortest Path in Salesforce's User Connections

Background: In Salesforce, user connections can be represented as a graph where users are nodes and their connections as edges. Finding the shortest path is crucial for analyzing user engagement and interaction.
Problem statement: Given a directed graph represented as an adjacency list, write a function to find the shortest path from a given starting user to all other users. The graph can contain cycles, and users can be connected to themselves. Return a dictionary where each user is mapped to its shortest distance from the starting user.
Function/class signature:
  • def shortest_path(graph: Dict[str, List[str]], start: str) -> Dict[str, int]:

Example 1:
Input: graph = {'A': ['B'], 'B': ['C', 'D'], 'C': ['D'], 'D': []}, start = 'A'
Output: {'A': 0, 'B': 1, 'C': 2, 'D': 2}
Explanation: The shortest path from 'A' to 'B' is 1, to 'C' is 2, and to 'D' is also 2.
Example 2:
Input: graph = {'A': ['B', 'C'], 'B': ['C'], 'C': ['A'], 'D': []}, start = 'A'
Output: {'A': 0, 'B': 1, 'C': 1, 'D': inf}
Explanation: 'D' is unreachable from 'A', thus returns inf.
Constraints:
  • Nodes in the graph: 1 ≤ |V| ≤ 10^5

  • Edges in the graph: 0 ≤ |E| ≤ 10^5

  • Start node will always be present in the graph.

coding Medium two pointers #5

5. Two Pointers — Find Pair with Given Sum in Customer Data

1. Background: In Salesforce, analyzing customer interactions is crucial for understanding their needs and improving services. The platform often needs to identify customer pairs that meet certain criteria, such as joint subscriptions.
2. Problem statement: You are given an array of integers representing customer IDs and an integer target that represents a desired sum of IDs. Your task is to find two distinct customers such that their IDs sum up to the target. Return the indices of these two customers in an array. If no such pair exists, return an empty array.
3. Function/class signature:
- def findCustomerPair(customer_ids: List[int], target: int) -> List[int]:
4. Example 1:
Input: customer_ids = [2, 7, 11, 15], target = 9
Output: [0, 1]
Explanation: Customer IDs 2 and 7 add up to 9.
5. Example 2:
Input: customer_ids = [3, 5, 2, 8], target = 10
Output: [0, 3]
Explanation: Customer IDs 3 and 7 add up to 10.
6. Constraints:
- 2 <= len(customer_ids) <= 10^4
- -10^9 <= customer_ids[i] <= 10^9
- -10^9 <= target <= 10^9
coding Easy hash map #6

6. [Hash Map] — Find the first unique character in a string

1. Background: In Salesforce, managing customer data efficiently is crucial. Analyzing data input, such as user feedback, often involves finding unique entries among repeated instances. This problem helps with such analysis.
2. Problem statement: You are given a string s representing some customer feedback. Your task is to find the first unique character in this string and return its index. If there are no unique characters, return -1.
3. Function/class signature:
- def first_unique_char(s: str) -> int:
4. Example 1:
- Input: "salesforce"
- Output: 0
- Explanation: The character 's' is the first unique character in the string.
5. Example 2:
- Input: "aabbcc"
- Output: -1
- Explanation: There are no unique characters in the string.
6. Constraints:
- 1 <= len(s) <= 1000
- s consists only of lowercase English letters.
coding Medium cache #7

7. CODING — Implement an LRU Cache

Background: In Salesforce, optimizing performance for frequently accessed data is critical, especially for applications dealing with large customer datasets. An LRU (Least Recently Used) Cache can help in efficiently managing memory by storing a limited number of data entries.
Problem statement: Design an LRUCache class that supports the following methods: get(key: int) -> int which retrieves the value of the key if the key exists in the cache, otherwise returns -1. The put(key: int, value: int) -> None method will insert a new key-value pair in the cache. If the number of keys exceeds the capacity, it should invalidate the least recently used key before inserting the new key.
Function/class signature:
  • def get(self, key: int) -> int:

  • def put(self, key: int, value: int) -> None:

Example 1:
  • Input: cache = LRUCache(2)

cache.put(1, 1)
cache.put(2, 2)
cache.get(1)
  • Output: 1

  • Explanation: The cache now contains two items: (1,1) and (2,2).

Example 2:
  • Input:

cache.put(3, 3)
cache.get(2)
  • Output: -1

  • Explanation: The cache reached its capacity and evicted key 2.

Constraints:
  • 1 <= capacity <= 3000

  • 0 <= key <= 10^4

  • 0 <= value <= 10^4

  • Function calls will occur at most 10^4 times.
coding Senior graph #8

8. [OA] Graph Traversal — Optimize Salesforce's lead qualification processing

Salesforce processes leads using a network of associated contacts. Implement a method to find the number of unique leads processing through a graph formed by contacts and their relationships.
Given a list of contacts represented as pairs of integers where each pair (a, b) indicates a connection between contacts a and b, your task is to find the total number of distinct leads reachable from a given starting contact.
Method Signature:
def countUniqueLeads(contacts: List[Tuple[int, int]], start: int) -> int:
Example 1:
Input: contacts = [(1, 2), (2, 3), (3, 4)], start = 1
Output: 4
Explanation: Starting from contact 1, the visible unique contacts are 1, 2, 3, and 4.
Example 2:
Input: contacts = [(1, 2), (2, 3), (3, 4), (5, 6)], start = 5
Output: 2
Explanation: Starting from contact 5, only contacts 5 and 6 are reachable.
Constraints:
  • 1 <= len(contacts) <= 10^5

  • 1 <= contacts[i][0], contacts[i][1] <= 10^6
coding Hard sliding window #9

9. [OA] Sliding Window — Optimize Salesforce's API request handling

To improve the performance of API requests and reduce response times, Salesforce needs to implement an algorithm to handle bursts of requests within a specific time frame.
Given a list of int timestamps representing the arrival times of API requests and an integer windowSize, your task is to determine the maximum number of API requests that can be handled within any windowSize seconds.
Method Signature:
def maxRequestsWithinWindow(timestamps: List[int], windowSize: int) -> int:
Example 1:
Input: timestamps = [1, 2, 3, 5, 6]
Output: 4
Explanation: The requests at times 1, 2, 3, and 5 can all be handled within a 5-second window (from time 1 to 6).
Example 2:
Input: timestamps = [1, 3, 6, 8, 10]
Output: 3
Explanation: The requests at times 6, 8, and 10 can all be handled within a 5-second window (from time 6 to 11).
Constraints:
  • 1 <= len(timestamps) <= 10^5

  • 0 <= windowSize <= 10^6

  • 0 <= timestamps[i] <= 10^6
system design Senior logging #10

10. [OA] Event Logging System Design — Manage Salesforce's event logging

Salesforce logs various events for user actions. We need to design a system that efficiently stores and retrieves log events based on time stamps and types. The system should support both real-time log retrieval as events occur and historical log query capabilities.
Class Definition:
class EventLogger:
  • def log(eventType: str, timestamp: int) -> None: — Records an event with its type and the time it occurred.

  • def getLogs(eventType: str, startTime: int, endTime: int) -> List[Tuple[str, int]]: — Retrieves events of a specific type that occurred between the given start and end time.


Example 1:
Input: logger = EventLogger(), logger.log('login', 1), logger.log('logout', 2), logger.getLogs('login', 0, 5)
Output: [('login', 1)]
Explanation: Returns the log of the 'login' event within the specified time frame.
Example 2:
Input: logger.log('click', 3), logger.getLogs('click', 1, 4)
Output: [('click', 3)]
Explanation: Returns the log of the 'click' event within the specified time frame.
Constraints:
  • 1 <= eventType.length <= 100

  • 0 <= timestamp <= 10^9
system design Senior caching #11

11. [OA] LRU Cache — Design a smart caching system for Salesforce's API

Salesforce's API serves numerous requests, making caching an essential feature to enhance performance. Implement an LRU (Least Recently Used) Cache to store API responses.
The cache should allow for the following operations: adding a new key-value pair and retrieving a value by key. In case of reaching the cache capacity, the least recently used item should get removed when a new item is added.
Class Definition:
class LRUCache:
  • def __init__(self, capacity: int): — Initializes the LRUCache with a positive size capacity.

  • def get(self, key: int) -> int: — Returns the value of the key if the key exists, otherwise returns -1.

  • def put(self, key: int, value: int) -> None: — Updates the value of the key if the key exists, otherwise adds the key-value pair to the cache.

If the number of keys exceeds the capacity, evict the least recently used key.
Example 1:
Input: LRUCache(2), cache.put(1, 1), cache.put(2, 2), cache.get(1)
Output: 1 (returns the value of key 1)
Example 2:
Input: cache.put(3, 3) (evicts key 2) then cache.get(2)
Output: -1 (key 2 was evicted)
Constraints:
  • 1 <= capacity <= 3000

  • 0 <= key <= 10^4

  • 0 <= value <= 10^4

Start practicing Salesforce questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free