Ntsh

What are the limitations of Flow that might lead you to choose Apex instead?

Salesforce Flow is a powerful tool for automating business processes with minimal or no code. However, it has several limitations that might lead you to use Apex instead – 1. Complex Business Logic Flow Limitation: Difficult or impossible to implement complex logic such as deeply nested if/else statements, recursion, or advanced calculations. Why Choose Apex: […]

What are the limitations of Flow that might lead you to choose Apex instead? Read More »

Explain Queueable vs Batch vs Future – which would you use to process 5M records and why

Future, Queueable, Batch — Key Differences 1. Future Methods 2. Queueable Apex 3. Batch Apex Scenario: Processing 5 Million Records To process 5 million records, I would use Batch Apex. Future and Queueable are good for smaller jobs, but they can’t handle millions of records because of governor limits. Batch Apex is designed for this

Explain Queueable vs Batch vs Future – which would you use to process 5M records and why Read More »

Difference between @wire, LDS, and Imperative Apex calls in LWC – and real use cases

This is one of the most frequently asked in Salesforce Developer interviews and also key in real-world Salesforce dev work. Let’s break it down in a simple but detailed way with use cases. 1. @wire (Reactive, Declarative) Example- Use cases – 2. LDS (Lightning Data Service) Example- Use cases 3. Imperative Apex Calls (Programmatic) Example-

Difference between @wire, LDS, and Imperative Apex calls in LWC – and real use cases Read More »

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 »