Salesforce Developer
500+ Salesforce Developer Interview Questions and Answers

Asked in Cognizant

Q. Write a trigger to update related Opportunity records when an account is updated.
Trigger to update Opportunities when an Account is modified in Salesforce.
Use 'after update' trigger on Account object to capture changes.
Query related Opportunities using 'SELECT Id FROM Opportunity WHERE AccountId = :Trigger.newMap.keySet()'.
Update Opportunity fields based on Account changes, e.g., Account Name.
Use 'update' DML operation to save changes to Opportunities.

Asked in Deloitte

Q. Write a trigger to update a contact when an account's phone number is changed.
Trigger to update contact when accounts phone changed
Create a trigger on Account object
Query for related Contacts
Update Contact phone field with Account phone field value
Salesforce Developer Interview Questions and Answers for Freshers

Asked in Infosys

Q. How do you make the child records read-only if the parent record's field is updated to a specific value?
Child records can be made read-only when parent record's field is updated using validation rules.
Create a validation rule on child object
Use ISCHANGED() function to check if parent field is updated
Use PRIORVALUE() function to get the previous value of parent field
Use ISBLANK() function to check if the previous value of parent field is blank
Use ISNEW() function to allow creation of child records
Use OR() function to combine all conditions
Throw an error message if all conditions...read more

Asked in Cognizant

Q. How many ways can asynchronous code be written in Salesforce?
There are multiple ways to write asynchronous code in Salesforce.
Using @future annotation
Using Queueable interface
Using Batch Apex
Using Platform Events
Using Asynchronous Apex REST Callouts

Asked in TCS

Q. Difference between Roles & Profiles, Difference between Workflow-ProcessBuilder-Flow,Types of Workflow and how to set them up,Trigger context variables
Explaining the difference between Roles & Profiles, Workflow-ProcessBuilder-Flow, types of Workflow, and Trigger context variables.
Roles define the level of access a user has to records in an organization, while profiles define the level of access a user has to objects and fields.
Workflow, Process Builder, and Flow are automation tools used to automate business processes in Salesforce.
Workflow rules are used to automate standard internal procedures and processes to save time ...read more

Asked in Infosys

Q. How do you call a controller method from JavaScript in a Visualforce page?
To call a controller method from JavaScript in a Visualforce page, use the actionFunction tag.
Create a controller method in the Apex class.
Add an actionFunction tag in the Visualforce page.
Call the actionFunction from JavaScript using its name.
Pass parameters to the controller method using the actionFunction tag.
Use the rerender attribute to update the page after the controller method is called.
Salesforce Developer Jobs




Asked in Infosys

Q. How do you load both parent and child records at a time using data loader?
Use data loader's parent-child functionality to load both parent and child records at once.
Create a CSV file with both parent and child records
Use the data loader's parent-child functionality to map the relationship between the two
Ensure that the parent records are loaded before the child records
Use the data loader's insert or upsert operation to load the data

Asked in TCS

Q. Batch class and its functions, use of stateful interface in batch class
Batch class is used to process large data sets in chunks. Stateful interface maintains state between batches.
Batch class implements Database.Batchable interface
It has three methods: start(), execute() and finish()
Stateful interface is used to maintain state between batches
Stateful variables can be declared outside of the execute() method
Example: Batch class to update all accounts with a specific field value
Share interview questions and help millions of jobseekers 🌟

Asked in Infosys

Q. What are collection variables and when do we use them in Apex?
Collection variables are used to store multiple values of the same data type in Apex.
Collection variables include Lists, Sets, and Maps.
Lists are ordered collections of elements that can contain duplicates.
Sets are unordered collections of unique elements.
Maps are collections of key-value pairs.
Collection variables are useful for iterating over multiple values and performing operations on them.
Example: List<String> names = new List<String>{'John', 'Jane', 'Bob'};
Example: Set<...read more

Asked in Cloud Analogy

Q. How do you remove leading whitespaces from a string in Python?
Python provides a built-in method to remove leading whitespaces from a string.
Use the lstrip() method to remove leading whitespaces from a string.
lstrip() method removes all whitespaces from the beginning of the string.
Example: string = ' Hello World' string.lstrip() Output: 'Hello World'
Asked in P2P SYSTEM

Q. 1. Write apex trigger on Account Object to update Contact Detail Field . 2. What is Governor Limit in salesforce . 3. What is Relationship in salesforce. 4. What is lookup relationship . 5. What is custom objec...
read moreAnswers to Salesforce Developer interview questions
1. Use trigger.new to get the updated account records and update the related contact detail field
2. Governor limits are the limits set by Salesforce to ensure efficient use of resources and prevent abuse
3. Relationship in Salesforce refers to the association between two objects
4. Lookup relationship is a type of relationship where one object has a reference to another object
5. Custom object is an object created by the user to...read more

Asked in Accenture

Q. Write a batch Apex class to update the account rating.
Batch code to update account rating
Create a batch class implementing Database.Batchable interface
Query for accounts with specific criteria
Update the rating field for each account
Execute the batch class using Database.executeBatch method

Asked in TCS

Q. what is salesforce,governer limits,profiles,roles,visualforce,apex
Salesforce is a cloud-based CRM platform. Governor limits are limits on resources. Profiles and roles control access. Visualforce and Apex are development tools.
Salesforce is a cloud-based CRM platform used for managing customer data and interactions.
Governor limits are limits on resources such as CPU time, database queries, and API calls.
Profiles and roles control access to data and functionality within Salesforce.
Visualforce is a development tool used for creating custom us...read more

Asked in IDFC FIRST Bank

Q. What are the types of integration available with Salesforce?
Salesforce offers various types of integration options to connect with external systems.
SOAP API: Allows integration with external systems using SOAP protocol.
REST API: Enables integration with external systems using RESTful web services.
Bulk API: Facilitates integration for large data volumes using batch processing.
Streaming API: Provides real-time integration by pushing data updates to external systems.
Outbound Messaging: Sends notifications to external systems using SOAP o...read more
Asked in Grenud

Q. Write a SOQL query to find the Team record where the Player record name is Virat Kohli and the Team name is India, assuming Team is the parent object and Player is the child object.
SOQL query to find player 'Virat Kohli' in team 'India' using parent-to-child relationship.
SOQL (Salesforce Object Query Language) is used to query Salesforce data.
In a parent-to-child relationship, you can query child records using a subquery.
The query structure for this scenario would be: SELECT Id, (SELECT Id FROM Players__r WHERE Name = 'Virat Kohli') FROM Team__c WHERE Name = 'India'.
Ensure that 'Players__r' is the correct relationship name for the child object in your S...read more

Asked in Infosys

Q. Write a trigger that follows best practices. When a new contact is inserted, check if the account has a primary contact. If not, insert the new contact as the primary contact. If a primary contact already exist...
read moreTrigger to ensure only one primary contact per account in Salesforce.
Use a before insert trigger to check for existing primary contacts.
Query the Account object to find if a primary contact exists.
If a primary contact is found, add an error to the contact record.
Use a Set to track account IDs for efficient lookups.
Example: 'if (existingContacts.size() > 0) { contact.addError('Already present'); }'

Asked in Virtusa Consulting Services

Q. If a SOQL query in a trigger fetches more than 50,000 records, how would you handle that?
To handle more than 50K records fetched by SOQL in trigger, use batch apex or pagination.
Use batch apex to process records in smaller chunks
Implement pagination to limit the number of records fetched at a time
Consider using selective SOQL queries to reduce the number of records fetched
Avoid using SOQL queries inside loops
Use query optimizer tool to optimize SOQL queries

Asked in Deloitte

Q. Describe a scenario where you would create a one-to-one relationship in Salesforce.
To create a 1 to 1 relationship in Salesforce, use a lookup field on the child object pointing to the parent object.
Create a lookup field on the child object that references the parent object.
Ensure that the lookup field has a unique constraint to enforce the 1 to 1 relationship.
Use validation rules or triggers to prevent multiple child records from being linked to the same parent record.

Asked in Cloud Analogy

Q. Write code to create the following pattern: {star pattern}
Code to create a star pattern
Use nested loops to print the pattern
The outer loop controls the number of rows
The inner loop controls the number of stars to print in each row
Use a combination of spaces and stars to create the pattern

Asked in Persistent Systems

Q. How does security work in Apex? For example, if a user does not have access to the Phone field, how does the query SELECT id, Name, Phone from Account WITH_SECURITY_ENFORCED work?
In Apex, security is enforced by default. If a user doesn't have access to a field, they won't be able to query it.
In Apex, security is enforced by default, meaning that users can only access data they have permission to see.
If a user doesn't have access to the Phone field in the Account object, they won't be able to query it even with WITH_SECURITY_ENFORCED.
The SELECT id, Name, Phone from Account WITH_SECURITY_ENFORCED query will only return the id and Name fields for users ...read more

Asked in Espire Infolabs

Q. Describe the standard objects in Salesforce and how you would insert data into them.
Standard objects and how to insert data in Salesforce
Standard objects are pre-built objects in Salesforce such as Account, Contact, Lead, etc.
Data can be inserted into Salesforce using Data Loader, Apex Data Loader, or through API calls
Data can also be inserted manually through the Salesforce UI
Data can be inserted in bulk or one record at a time

Asked in Blue Flame Labs

Q. Can we use Trigger.new() in before and after triggers?
Yes, we can use trigger.new() in before & after trigger.
In before trigger, trigger.new() returns the records that are about to be saved.
In after trigger, trigger.new() returns the records that have been saved.
We can use trigger.new() to access and manipulate the records in the trigger context.

Asked in NTT Data

Q. When does APEX CPU Limit Exceeded error happens. What's the best practice to avoid getting this error?
APEX CPU Limit Exceeded error happens when code consumes too much CPU time. Best practices include optimizing code, reducing loops, and using asynchronous processing.
Avoid using nested loops and optimize code for better performance
Use asynchronous processing like @future or Queueable to offload CPU intensive tasks
Limit the use of SOQL queries inside loops to reduce CPU consumption

Asked in TCS

Q. What is decorator in LWC? Data passing between LWC? Sales and Service Cloud? What is order of execution? Which tool used for deployment? Case management process? about salesforce integration? Flow in Salesforce...
read moreDecorators in LWC are used to modify the behavior of a component. Data passing between LWC components can be done using properties and events. Salesforce Sales and Service Cloud are CRM platforms. Order of execution in Salesforce refers to the sequence in which operations are performed. Deployment in Salesforce is done using tools like Salesforce DX. Case management process involves tracking and resolving customer issues. Salesforce integration allows different systems to com...read more

Asked in Blue Flame Labs

Q. What is trigger context?
Trigger context refers to the execution context of a trigger in Salesforce.
Trigger context provides information about the record(s) that caused the trigger to execute.
It includes details like the trigger event type, the old and new versions of the records, and the user who caused the trigger to execute.
The trigger context is accessed using the Trigger class in Apex.
Example: Trigger context can be used to perform specific actions based on the type of trigger event, such as bef...read more

Asked in NTT Data

Q. Write a SOQL query to fetch the values of description field from the Account. Why does "the description field cannot be filtered in the query call"?
SOQL query to fetch description field from Account and reason for inability to filter
SOQL query: SELECT Description FROM Account
Description field is not filterable because it is a long text field
Long text fields cannot be filtered in SOQL queries

Asked in Virtusa Consulting Services

Q. Write a trigger. There are three objects: A (parent), B (child), and C (grandchild). When the grandchild (C) is updated, update the description of A with the description of C.
Write a trigger to update the description field on the parent object when the grandchild object is updated.
Create a trigger on the grandchild object
Use a SOQL query to retrieve the parent object
Update the description field on the parent object with the grandchild's description

Asked in Cloud SynApps

Q. Write a trigger that, when inserting a contact (application user), checks if the contact is associated with any account. If not, assign it to a 'Test Account'. If the 'Test Account' does not exist, create it, e...
read moreTrigger to assign or create a Test Account for Contacts without an associated Account.
Use an 'after insert' trigger on the Contact object.
Query for existing 'Test Account' to avoid duplicates.
If no Account is associated with the Contact, assign the existing 'Test Account'.
If no 'Test Account' exists, create one and associate it with the Contact.
Ensure to handle bulk inserts to avoid governor limits.

Asked in Capgemini

Q. How to invoke flows - using other flows and Apex. How do we invoke an apex class from a flow and pass variables?
Flows can be invoked using other flows and Apex. Apex classes can be invoked from a flow by using invocable methods and passing variables as input parameters.
To invoke a flow from another flow, use the 'Launch Flow' element in the Flow Designer.
To invoke an Apex class from a flow, create an invocable method in the Apex class and annotate it with @InvocableMethod.
Pass variables from a flow to an Apex class by defining input parameters in the invocable method.
In the flow, use t...read more

Asked in Virtusa Consulting Services

Q. Describe a trigger scenario where the count of child records is updated on the parent record using a trigger. How do you bulkify a trigger?
Bulkify a trigger to count child records and update parent records efficiently in Salesforce.
Use a Map to store parent records and their corresponding child counts.
Query all relevant child records in a single SOQL query to avoid governor limits.
Iterate through the child records and populate the Map with counts.
Update the parent records in bulk after processing all child records.
Example: If a parent Account has multiple Contacts, count them and update a custom field on the Acc...read more
Interview Questions of Similar Designations
Interview Experiences of Popular Companies





Top Interview Questions for Salesforce Developer Related Skills

Calculate your in-hand salary
Confused about how your in-hand salary is calculated? Enter your annual salary (CTC) and get your in-hand salary


Reviews
Interviews
Salaries
Users

