Top 10 Salesforce Interview Questions: QnA Part 2

Explore the second part of our Salesforce Interview Questions series, covering crucial topics such as Enum Apex Class, Custom Setting, Asynchronous Apex, Batch Apex, Future Methods, Queueable Apex, Scheduled Apex, CRON Expression, and Salesforce Integration. Elevate your understanding of Salesforce concepts with detailed answers and examples

1.What is Enum Apex Class?

Enum in Apex is a special class representing a fixed set of constants using the “enum” keyword.
Example: public enum Fruit {Apple, Banana, Orange}.

2.What is Custom Setting?

Salesforce is a mechanism to store custom data at the organization, profile, or user level, providing a flexible and customizable way to manage application settings.

Types:

1.List Custom Settings

2.Hierarchy Custom Settings

3.What is Metadata?

Customizable information that defines the structure and behavior of the platform, such as objects, fields, workflows, and configurations, managed through the Salesforce setup menu.

4.What is a Test Class?

A test class in Salesforce is code written to validate the functionality of Apex code, ensuring proper execution and avoiding unintended side effects. Annotated with @isTest.
Validate Apex Code using various test methods such as @testSetup.

Examples: Unit tests, Integration tests, System tests.

5.What is Asynchronous Apex?

Asynchronous Apex in Salesforce allows the execution of processes outside the request-response cycle.

Types:

i. Future methods
ii. Queueable Apex
iii. Batch Apex
iv. Scheduled Apex.

6.What is Batch Apex?

In Salesforce, Batch Apex is a mechanism for processing large sets of records asynchronously in small, manageable chunks, enabling efficient and scalable data processing.

Features:
Stateful: Retains the state between batches
Stateless: Doesn’t maintain state between batches

Example: Processes Account records in batches, appending “_Batch Processed” to their names.

// Program

public class MyBatch implements Database.Batchable {
    public Database.queryLocator start(Database.BatchableContext context) {
    return Database.getQueryLocator('SELECT Id, Name FROM Account');
    }
public void execute(Database.BatchableContext context, List scope) {
    // Batch Processing logic here
    for (Account acc : scope) {
    acc.Name += '_Batch Processed';
    }
    update scope;
}
public void finish(Database.BatchableContext context) {
    // Finalization logic here
   }
}

// Execute the Batch
MyBatch myBatch = new MyBatch();
Database.executeBatch(myBatchInstance, 200); // 200 is batch size

7.What are Future Methods?

In Salesforce, Future Methods are annotated with @future, serving as asynchronous Apex methods that enable the execution of code outside the current transaction, allowing non-blocking operations.

// Examples

public class MyFutureClass {
    @future
    public static void myFutureMethod(String input) {
    // Asynchronous logic, processing the input
    System.debug('Async Processed: ' + input);
    }
}

// Execute
MyMethodClass.myFutureMethod('Hello, Asynchronous');

Types:

i. Stateless: Independent of transaction stateTypes:

// Example

public static void statelessFutureMethod(String input) {
    // Stateless asynchronous logic
    System.debug('Stateless Future Processed: ' + input);
}

ii. Stateful: Maintains transaction state

// Example

@Future(callout = true)
public static statefulFutureMethod(String input) {
    // Stateful asynchronous logic with Callouts
    System.debug('Stateful Future Processed: ' + input);
}

8.What is Queueable Apex?

Queueable Apex in Salesforce enables asynchronous processing, allowing the execution of jobs in the background for handling complex or long-running tasks.

9.What is Scheduled Apex?

Scheduled Apex in Salesforce allows you to run Apex classes at specified intervals to automate repetitive tasks.

10.What is CRON Expression?

A CRON expression is a string representing a schedule, specifying timing for recurring tasks in a fixed format. Commonly used in job scheduling, it consists of seven fields:

String cronexpress = '1st, 2nd, 3rd, 4th, 5th, 6th, 7th';

1st - Seconds (0-59)
2nd - Minutes (0-59)
3rd - Hours (0-23)
4th - Day-of-Month (1-31) (L, W allowed)
5th - Month (1-12) or (JAN-DEC)
6th - Day-of-Week (1-7) or (SUN, MON, TUE, WED, THU, FRI, SAT)
7th - Year (optional) (1970-2099)

11.What is Salesforce Integration?

Salesforce integration is the process of combining Salesforce data and functionalities with those of another application, creating a seamless and unified experience for users.

Types:

i. Inbound (Receiving data into Salesforce): Integration with an external service via SOAP (Simple Object Access Protocol)

ii. Outbound (Sending data from Salesforce): Receiving data from an external source using REST (Representational State Transfer)

Read More : Top 30 Salesforce Interview Questions: QnA Part 1
Read More : Top 30 Salesforce Interview Questions: QnA Part 3

Keywords: Salesforce Interview Questions, Enum Apex Class, Custom Setting, Metadata, Test Class, Asynchronous Apex, Batch Apex, Future Methods, Queueable Apex, Scheduled Apex, CRON Expression, Salesforce Integration.

Leave a Comment