Here are a few common Salesforce interview questions along with their answers:
Question 1: Difference between Master-Details and Lookup Relationship in Salesforce
A Master-Detail relationship is a type of parent-child relationship where the child record (detail) is tightly linked to the parent record (master). Deleting the master record automatically deletes its child records. In contrast, a Lookup relationship is a looser association where the child can exist independently of the parent, and deleting the parent does not affect the child records.
Question 2: What is the Junction Object?
A Junction Object is an intermediate custom object used to connect two objects in a many-to-many relationship. It facilitates complex data modeling, enabling users to relate multiple records from one object to multiple records in another object.
Question 3: Why do we use Master-Detail Relationships instead of Lookup Relationships?
Master-Detail relationships offer cascading delete, roll-up summary fields, and enforce mandatory parent record selection. This makes them ideal for scenarios where data integrity and consistency are critical.
Question 4: Write a Trigger If the Account has the opportunity then the user can’t delete the Account or if the Account has no opportunity then the user can delete the Account Record.
trigger PreventAccountDelete on Account (before delete) {
// Collect all Account Ids from the trigger context
Set<Id> accountIds = new Set<Id>();
for (Account acc : Trigger.old) {
accountIds.add(acc.Id);
}
// Check if any related Opportunities exist
Map<Id, Integer> opportunityCountMap = new Map<Id, Integer>();
for (Opportunity opp : [SELECT AccountId, COUNT() FROM Opportunity WHERE AccountId IN :accountIds GROUP BY AccountId]) {
opportunityCountMap.put(opp.AccountId, opp.Count);
}
// Loop through the Accounts and prevent deletion if Opportunities exist
for (Account acc : Trigger.old) {
if (opportunityCountMap.containsKey(acc.Id) && opportunityCountMap.get(acc.Id) > 0) {
acc.addError('You cannot delete an Account with associated Opportunities.');
}
}
}
Question 5: Write a Validation rule to make a required field on the opportunity object if the stageName is changed and one field value is blank then show an error.
AND(
ISCHANGED(StageName),
ISBLANK(Your_Custom_Field__c)
)
Question 6: I have 10 users and all users have the same profile. I want to restrict the delete permission from the two users. so, how can we achieve that?
Question 7: How many types of reports are available in Salesforce?
Salesforce provides various types of reports, including Tabular Reports, Summary Reports, Matrix Reports, and Joined Reports. Each type caters to specific data visualization needs.
Question 8: What is the Wrapper class and why do we use it?
Question 9: What is the trigger and how many types of events are in a trigger?
Question 10: What is the Difference between newMap and oldMap?
In a trigger context, newMap
represents the new version of records, and oldMap
represents the old version of records. These maps are useful for comparing changes and performing actions based on before-after record states.
Question 11: What is the difference between trigger.new and trigger.old?
trigger.new
contains the new version of records, while trigger.old
contains the old version of records. They are used to perform actions based on changes made to records during trigger execution.
Question 12: How the Leads is generated?
Question 13: what happens when the lead is converted in the opportunity, Account, and Contact?
Question 14: How to map the email field of the Lead to the email field of the opportunity?
Question 15: What is Custom Permission and How to retrieve the Custom Permission in Apex?
Custom Permissions provide a way to define user permissions beyond standard profiles and permission sets. They can be retrieved in Apex using the FeatureManagement.checkPermission
method.
Question 16: How many ways to share records in Salesforce?
Salesforce provides various record-sharing mechanisms, including Organization-Wide Sharing Defaults, Role Hierarchy, Sharing Rules, Manual Sharing, and Apex Managed Sharing.
Question 17: How many types of permission are in Salesforce?
Salesforce offers several types of permissions, such as Object Permissions, Field Permissions, Record-Level Permissions, and Apex Permissions.
Question 18: How to route the case to the Multiple agent?
Question 19: Which object comes under Sales and Service Cloud? Please Write the Name of these objects.
Question 20: What is the Roll-up Summary? What are the functions we use in the roll-up summary field?
Roll-up Summary fields perform calculations on child records and display aggregated values on the parent record. Functions include SUM, COUNT, MIN, and MAX.
Question 21: What is the difference between Batchable and Schedulable classes?
Batchable classes are used for processing large data sets asynchronously, while Schedulable classes are used to schedule Apex jobs to run at specified intervals.
Question 22: What is the use of Aggregate Query in Apex and what will be the data type of COUNT()?
Question 23: If one trigger and one flow at the same object. then, what will be run first trigger or flow?
Question 24: Write a SOQL Query to fetch the Email id of the user who has created the account record.
SELECT Owner.Email
FROM Account
WHERE CreatedById = :UserInfo.getUserId()
Question 25: Write a SOQL Query to fetch all the Accounts where createdDate is Equal to the LastModifiedDate.
Question 26: What is the sandbox and how many types of sandbox available?
A Sandbox in Salesforce is a dedicated copy of the production organization used for testing, development, and training purposes. It allows Salesforce administrators, developers, and quality assurance teams to experiment, build, and test new features, configurations, and code changes without impacting the live production environment. Sandboxes are crucial for ensuring that changes are thoroughly tested before being deployed to the production instance.
Types of Sandboxes: Salesforce offers several types of Sandboxes, each serving specific needs and providing varying levels of functionality. The main types of Sandboxes available are as follows:
- Developer Sandbox: The Developer Sandbox is primarily intended for individual developers. It provides a personal workspace for development and testing activities. The Developer Sandbox is a single-user environment, and its data is refreshed from the production organization manually by the developer.
- Developer Pro Sandbox: The Developer Pro Sandbox is similar to the Developer Sandbox but with more storage space and capabilities.
- Partial Copy Sandbox: The Partial Copy Sandbox is ideal for testing configurations and code with a representative subset of data from the production environment. It includes a limited number of records from selected objects. This type of Sandbox is useful for testing with realistic data scenarios.
- Full Sandbox: The Full Sandbox is a complete copy of the production environment, including all data and configurations. It is primarily used for extensive testing, user training, and validating complex changes before deploying them to production.
One Response
Thank you so much for such detailed answers of the questions. It really helps to understand the logic.