Application Development & Apex Flashcards

1
Q

Q. What is Apex in Salesforce?

A

A. Apex is a strongly-typed, object-oriented programming language used for executing business logic and transaction control in Salesforce.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Q. What programming languages is Apex similar to?

A

A. Apex is similar to Java and C#.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Q. Where is Apex code executed?

A

A. Apex code runs on Salesforce’s multi-tenant cloud infrastructure.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Q. What are the key features of Apex?

A
  • Object-oriented programming
  • Strongly typed language
  • Integrated with Salesforce database
  • Bulk processing support
  • Transactional control
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Q. What are the primitive data types in Apex?

A

A. Integer, Double, Long, Date, DateTime, Boolean, String, Blob, and ID.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Q. How do you define a class in Apex?

A

public class MyClass {
public String myVariable;

public void myMethod() {
    System.debug('Hello Apex');
} }
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Q. What are collections in Apex?

A

A. Collections in Apex include Lists, Sets, and Maps.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Q. What is the difference between Lists, Sets, and Maps in Apex?

A
  • Lists: Ordered collection allowing duplicates.
  • Sets: Unordered collection that does not allow duplicates.
  • Maps: Key-value pairs for fast lookup.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

Q. How do you declare a List in Apex?

A

List<String> myList = new List<String>{'Apple', 'Banana', 'Cherry'};</String></String>

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

Q. What is an Apex trigger?

A

A. A trigger is Apex code that runs before or after a record is inserted, updated, deleted, or undeleted.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

Q. What are the two types of triggers in Salesforce?

A

A. Before triggers (modify records before saving) and After triggers (access record values after saving).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Q. What is a bulkified trigger?

A

A. A trigger designed to process multiple records efficiently to avoid governor limits.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

Q. What is an example of a basic Apex trigger?

A

trigger AccountTrigger on Account (before insert, before update) {
for (Account acc : Trigger.new) {
acc.Name = acc.Name + ‘ - Updated’;
}
}

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Q. How do you prevent recursion in Apex triggers?

A

A. By using static variables in a helper class.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Q. What is SOQL?

A

A. Salesforce Object Query Language (SOQL) is used to query records from Salesforce objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Q. How do you write a basic SOQL query?

A

List<Account> accList = [SELECT Id, Name FROM Account WHERE Industry = 'Technology'];</Account>

17
Q

Q. What are governor limits for SOQL queries?

A
  • Maximum 50,000 records retrieved
  • Maximum 100 SOQL queries per transaction
18
Q

Q. What is the difference between SOQL and SOSL?

A
  • SOQL: Query specific fields in a single object.
  • SOSL: Search across multiple objects using full-text search.
19
Q

Q. What are DML operations in Apex?

A

A. Insert, Update, Delete, Upsert, Undelete.

20
Q

Q. What is an example of an Insert operation in Apex?

A

Account acc = new Account(Name = ‘New Account’);
insert acc;

21
Q

Q. What is an upsert operation?

A

A. A DML operation that inserts a new record if it does not exist, or updates an existing record.

22
Q

Q. What are governor limits for DML operations?

A
  • Maximum DML statements: 150 per transaction
  • Maximum records processed: 10,000 per transaction
23
Q

Q. What are governor limits in Salesforce?

A

A. Limits imposed by Salesforce to ensure fair resource usage in a multi-tenant environment.

24
Q

Q. What are key governor limits in Apex?

A
  • SOQL queries: Max 100 per transaction
  • DML statements: Max 150 per transaction
  • CPU time: Max 10 seconds
  • Heap size: Max 6 MB synchronous, 12 MB asynchronous
25
Q

Q. How can you optimize Apex code to handle governor limits?

A
  • Use bulkified queries
  • Use collections instead of multiple queries
  • Avoid nested loops with SOQL/DML
  • Use batch processing for large datasets
26
Q

Q. What is Asynchronous Apex?

A

A. Apex code that runs in the background without blocking user operations.

27
Q

Q. What are the different types of Asynchronous Apex?

A
  • Future Methods
  • Batch Apex
  • Queueable Apex
  • Scheduled Apex
28
Q

Q. What is a Future method in Apex?

A

A. A method that runs asynchronously to handle long-running operations.

29
Q

Q. What is an example of a Future method?

A

@future
public static void updateAccounts() {
List<Account> accList = [SELECT Id FROM Account];
for (Account acc : accList) {
acc.Name += ' - Updated';
}
update accList;
}</Account>

30
Q

Q. What is the purpose of unit testing in Apex?

A

A. To validate code behavior, ensure stability, and meet Salesforce’s 75% code coverage requirement.

31
Q

Q. What is an example of an Apex test class?

A

@isTest
private class AccountTest {
@isTest
static void testAccountInsert() {
Account acc = new Account(Name=’Test Account’);
insert acc;
System.assertNotEquals(null, acc.Id);
}
}

32
Q

Q. What are best practices for writing Apex code?

A

A. - Use bulkified queries and DML statements
- Follow the Single Responsibility Principle
- Use custom settings for configurable values
- Implement error handling using try-catch blocks
- Write unit tests with at least 75% code coverage

33
Q

Q. How do Apex and LWC communicate?

A

A. LWC calls Apex methods using @AuraEnabled annotation.

34
Q

Q. What is an example of an Apex method used in LWC?

A

public with sharing class AccountController {
@AuraEnabled(cacheable=true)
public static List<Account> getAccounts() {
return [SELECT Id, Name FROM Account LIMIT 10];
}
}</Account>

35
Q

Q. How do you ensure Apex security?

A
  • Enforce CRUD and FLS (Field-Level Security)
  • Use WITH SECURITY_ENFORCED in SOQL queries
  • Avoid hardcoded IDs
  • Use sharing rules and security models