Skip to main content

1. How do you invoke an Apex class in a Lightning web component, and what are the different methods and their use cases?
Ans:  Invoke Apex methods in a Lightning web component by using the wire service or imperatively. You can achieve this by wiring a property, wiring a function, or calling a method imperatively. The Apex method should be static, global, or public, and annotated with @AuraEnabled for exposure to the Lightning web component.

2. What does mixed DML refer to?
Ans:  A Mixed DML operation error arises when you attempt to modify both a Setup Object and a non-Setup Object within the same transaction. For instance, updating an Account record and a User record simultaneously could trigger this error.

3. How do Stateful and Stateless batch jobs differ?
Ans:  For Stateful Batch Apex, if your batch process requires shared information between transactions, implement the Stateful interface in the Batch Apex class. This preserves static and instance variables between transactions. For example:

global class SummarizeAccount implements Database.Batchable<sObject>, Database.Stateful {

In short, if you need to send an email to check the number of records passed and failed in the batch job counter, you can use a Stateful batch job. Create a counter and share/use it in each execute method.

On the other hand, Stateless Batch Apex, which is the default state, provides a fresh copy of your object for each execution of the execute method. All fields of the class are initialized, both static and instance. For instance:

global class SummarizeAccount implements Database.Batchable<sObject> {

4. What does the term “Batch job” mean in Salesforce?
Ans:  Batch class in Salesforce is employed for handling large volumes of records within standard processing constraints. Batch Apex allows the asynchronous processing of records to comply with platform limits. It’s the ideal solution for tasks like data cleansing or archiving when dealing with a substantial number of records. In Batch Apex, each transaction begins with a fresh set of governor limits, facilitating adherence to execution limits.

5. What does Async Apex refer to in Salesforce, and what are the different methods available for asynchronous processing?
Ans:  an asynchronous operation implies a process that functions independently of other processes.

For achieving asynchrony in Salesforce,

Schedule & Batch jobs
Change Data Capture – Apex Triggers (Summer ’19)
Platform Events – Event-Based
Continuations (UI)

6. Can you explain the Apex Trigger Framework in Salesforce and outline the various Trigger Frameworks available?
Ans:  Trigger Handler Pattern, Trigger Framework using a Virtual Class, Trigger Framework using an Interface, and an architecture framework designed for trigger handling in the Apex hours Trigger Framework in Salesforce sessions.

7. Can you provide a small explanation of what an Apex Trigger is, and in what scenarios should one use Apex Triggers in Salesforce?
Ans:  A trigger is an automatic procedure in a database triggered by specific events. In Salesforce, Apex triggers allow you to execute custom actions before or after record events like insertions, updates, or deletions. You might opt for Apex Triggers when dealing with:

Complex logic beyond declarative tools’ capabilities.
Logic tied to Data Manipulation Language (DML) operations.
Operations involving unrelated objects.
Integrations with external systems.

8. Can you provide a concise overview of the best practices for writing Apex code in Salesforce?
Ans:  When working with Apex code in Salesforce, it’s crucial to follow best practices for efficient and scalable solutions. Some key recommendations include:

Bulkify Apex Code
Avoid SOQL & DML inside for Loop
Manage Large Data Sets
Utilize Map of Sobject
Leverage Limits Apex Methods
Refrain from Hardcoding IDs
Use Database Methods for DML operations
Implement Exception Handling
Stick to One Trigger per Object per event
Consider Asynchronous Apex when needed.

9. What is Apex, and when is it preferable to use Apex over Flow in Salesforce?
Ans:  Apex is Salesforce’s programming language, offering strong typing and object-oriented capabilities for executing flow and transaction control statements. A typical strategy involves using Apex to handle DML activities while relying on declarative tools for non-DML tasks, such as email alerts and in-app alerts. Care should be taken to avoid conflicts in Apex implementations.

10. What is the purpose of a wrapper class in Salesforce?
Ans:  A wrapper or container class is a custom object in Salesforce defined by a developer to store collections of other objects.

Subscribe For More Updates


Join our mailing list to receive the latest news and updates from our team.

You have Successfully Subscribed!