Ntsh

How do you optimize a SOQL query that is hitting governor limits with large data

When a SOQL query hits governor limits (like 50,000 record limit or too many queries in one transaction), you need to optimize it. Here are some strategies: Ways to Optimize SOQL Queries 1. Use Selective Queries (Filters) – 2. Use LIMIT & ORDER BY – Always limit the number of records if you don’t need […]

How do you optimize a SOQL query that is hitting governor limits with large data Read More »

How do you handle Mix DML errors when creating Users & Accounts in the same transaction?

In Salesforce, Mix DML error happens when you try to perform DML on setup objects (like User, Profile, PermissionSetAssignment, etc.) and non-setup objects (like Account, Opportunity, etc.) in the same transaction. So if you create a User and an Account in the same transaction, you’ll hit a MIXED_DML_OPERATION error. Why the Mixed DML Error Occurs?

How do you handle Mix DML errors when creating Users & Accounts in the same transaction? Read More »

Write a trigger that updates the Account ‘Number of Opportunities’ field when an Opportunity is inserted, updated, or deleted.

This Apex trigger ensures that the custom field Number_of_Opportunities__c on the Account object always reflects the current number of related Opportunity records. It runs after insert, update, and delete operations on Opportunity. Trigger- Apex class-

Write a trigger that updates the Account ‘Number of Opportunities’ field when an Opportunity is inserted, updated, or deleted. Read More »

When a custom object is created in Salesforce, how many associated objects are automatically created

When you create a custom object in Salesforce, Salesforce does automatically generate a few related system objects behind the scenes- Suppose a custom object named Test_Obj is created. The following system objects might also be generated automatically: Test_Obj__ChangeEvent, Test_Obj__History, and Test_Obj__Share. However, the creation of these system objects depends on specific conditions, such as whether

When a custom object is created in Salesforce, how many associated objects are automatically created Read More »

The major differences between Queueable and Batch Apex in Salesforce

Batch Apex Batch Apex is designed for processing large volumes of data by dividing the workload into smaller, manageable batches. It’s implemented by defining a class that implements the Database.Batchable interface, with the required start, execute, and finish methods Advantages: Governor Limits Reset per Batch-Each batch runs in its own transaction, which means governor limits

The major differences between Queueable and Batch Apex in Salesforce Read More »

Write a trigger to update a field on a child record to a default value if the child record is the only child of the parent.

Let’s say – The parent object is Account, The child object is Contact, We want to update the child field Status__c to ‘Primary’ only if that contact is the only contact related to the parent Account. Trigger: Key Concepts:

Write a trigger to update a field on a child record to a default value if the child record is the only child of the parent. Read More »

How to Count Contacts on Each Account Using Trigger

Count related contacts on each Account in Salesforce using a custom Apex Trigger. A simple solution for real-time rollups. This trigger runs after insert, update, or delete operations on the Contact object. It collects all relevant Account IDs and queries the number of Contacts for each, updating a custom field called Number_of_Contacts__c on the Account. This approach

How to Count Contacts on Each Account Using Trigger Read More »

Salesforce Developer Interview Questions

Prepare for your next Salesforce developer interview with these top questions and expert answers. Covers Apex, Lightning, integrations, and real-world scenarios to help you succeed. Admin (Configuration & Setup) Q:1. When would you choose a Lookup relationship over a Master-Detail and why? Ans: You choose a Lookup relationship over a Master-Detail relationship when you want

Salesforce Developer Interview Questions Read More »