Introduction to Apex Flashcards

1
Q

What is Apex?

A

Apex is Salesforce’s case-insensitive, cloud-hosted, Java-like, multitenant-aware, object-oriented, proprietary, strongly-typed, versioned programming language

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

What is a class?

A

a class is a template for objects that contains the methods (i.e. functions) that will define an object’s behavior and the variables that will hold an object’s state

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

What is an object?

A

an object is an instance of a class that has state (things that it knows about itself) and behavior (things that it can do)

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

What are the two types of type casting?

A

Explicit Type Casting

Implicit Type Casting

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

What is Explicit Type Casting?

A

Explicit Type Casting

  • we convert between unrelated data types by invoking conversion methods
  • many of the classes representing Apex variables have methods to convert values between data types
  • we can also convert between related data types by putting the desired data type in parentheses after the assignment operator

String a = ‘1’;

Integer b = Integer.valueOf(a);

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

What is Implicit Type Casting?

A

Implicit Type Casting

  • done automatically by language
  • two types

casting between numeric primitive data types (hierarchy)

Integer can convert to => Long… => Double… => Decimal

casting between Ids and Strings

Integer a = 1;

Decimal b = a;

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

What are Lists?

A
  • comma-separated, ordered, indexed groups of values (i.e. elements) that all share the same data type
  • because Lists are ordered and indexed, we can access individual elements through their index in the List and the List can contain duplicate values
  • Lists are zero-indexed,
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

Can you create a new list shoppingList and populate it with a “Cereal” and “Milk”?

A

List shoppingList = new List();
‘Cereal’,
‘Milk’
};

OR

List shoppingList = new List();
shoppingList.add(‘Cereal’);
shoppingList.add(‘Milk’);

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

What are sets? What methods does it have?

A

unordered collections and therefore must contain unique values

  • add() - add element to set
  • size() - returns size of set
  • contains() - returns true/false
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is a Map?

A

groups of key-value pairs where each key must be unique, but we can have duplicate values

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

What do the following Control Flow do?

  • Conditional Statements
  • Switch Statements
  • While and Do Loops
  • For Loop
A

Conditional Statements

if ([Boolean_condition])

// Statement 1

else

// Statement 2

Switch Statements

switch on expression {

when value1 {

// code block 1

} when value2 {

code block 2

} when else { // default block, optional

// code block 4

}

}

While and Do Loops

while (condition) {

code_block

}

do {

code_block

} while (condition);

For Loop

Traditional

for (init; exit_condition; iterator) {

code_block

}

For Loop to iterate through Lists and Sets

for (variable : list_or_set) {

code_block

}

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