Apex Code 33% Flashcards

1
Q

What does it mean that Apex is an integrated language?

A

That DML SOQL, SOSL are all integrated and can be used in the code.

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

What does it mean that Apex is a strongly typed language?

A

That variables must be declared with a datatype.

int a = 10;

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

Apex or Point and Click:

  1. Create Web services
  2. Create email services
  3. Perform complex validation over multiple objects
  4. Create complex business processes that are not supported by workflow
A
  1. Apex
  2. Apex
  3. Apex
  4. Apex
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Apex or Point and Click:
Create custom transactional logic (logic that occurs over the entire transaction, not just with a single record or object)

A

Apex

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

Apex or Point and Click:
Attach custom logic to another operation, such as saving a record, so that it occurs whenever the operation is executed, regardless of whether it originates in the UI, a VF page or from the Web Services API.

A

Apex

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

True/False: All variables in Apex allow null as a value and are initialized to null if they are not assigned another value.

A

True.

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

In Apex, all variables and expressions have a data type. What are the five kinds of data types in Apex?

A
  1. Primitives (int, String)
  2. sObject
  3. Collections (Set, List, Map)
  4. Objects created from user-defined or system-defined apex classes
  5. Enums
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

True/False: Lists:

  1. Lists contain implicit keys, explicit values
  2. Is not ordered
  3. Values must be unique
  4. Useful for storing the results of a DB query
A
  1. True
  2. False - Lists have ordered values
  3. False
  4. True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

True/False: Maps:

  1. Maps contain key, value - pairs
  2. Is not ordered
  3. Values must be unique
  4. Useful for caching records indexed by ID
A
  1. True
  2. True
  3. False - Keys must be unique
  4. True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

True/False: Sets:

  1. Sets contain values
  2. Is not ordered
  3. Values must be unique
  4. Useful as a lookup criteria for relationship-based SOQL query
A
  1. True
  2. True
  3. True
  4. True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

True/False: Lists can only contain Primitives and sObjects.

A

False.

Lists can contain Primitives, sObjects, objects created from Apex classes and collections.

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

True/False: Sets can only contain sObjects.

A

False.

Sets can only contain primitives.

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

True/False: the key, value pair of Maps can be:

  1. Primitive to Primitive
  2. Primitive to sObject
  3. Primitive to Collection
A
  1. True
  2. True
  3. True
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Apex classes: What is the difference between:

  1. private myClass
  2. public myClass
  3. global myClass
A
  1. Classes cannot be referenced by any Apex code outside of the class in which they are defined.
  2. Classes can be called within the same org.
  3. Classes can be called by all Apex code everywhere. (e.g. webservices)
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

Apex classes: What is the difference between:

  1. public virtual myClass
  2. public abstract myClass
A
1. Apex supports virtual classes and methods. use "extend" to subclass a virtual class.
Note, methods derived from a virtual class can be overridden, but doesn't have to be.
2. Apex supports abstract classes. Methods are defined, but implemented in the subclass.
Note, methods derived from an abstract class must be overridden.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Apex classes: What is the difference between:

  1. public with sharing myClass
  2. public without sharing myClass
A
  1. With sharing or user context limits the code to access the records that the user executing the code has access to - respects the sharing model.
  2. Without sharing or system context - default - allows the code to access all records. - ignores the sharing model.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

True/False: A class can only extend one other class, but can implement more than one interface.

A

True.

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

True/False: User-defined methods can be polymorphic.

A

True.

A method named myMethod can be implemented two times with a different number of parameters.

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

True/False: User-defined methods can be declared as static when defined in a Trigger.

A

False.

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

True/False: In Apex, all classes and methods are final by default. By default, classes may not be extended to create sub-classes, and methods may not be overridden within sub-classes.

A

True.

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

True/False: A class cannot have a more restrictive access modifier than one of its methods or attributes.

A

True.

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

True/False:

  1. Only classes that are extending from virtual or abstract classes can use super
  2. You can only use super in methods that are designated with the override keyword.
A
  1. True

2. True

23
Q

What does the final keyword mean?

A

Constants that are defined using the final keyword can be assigned at most once, either in the declaration itself or with a static initializer method if the constant is defined in a class.

24
Q

What is a statement in Apex?

A

Any coded instruction that performs an action. I.E. Loops, Locking, DML calls, Transaction Control etc.

25
Q

True/False: Classes with @isTest annotation can only contain test methods.

A

True

26
Q

What is the advantage of having a separate class for testing?

A

Classes defined with @isTest doesn’t count against the limits.
Note, you can also add the @isTest annotation to methods inside normal classes.

27
Q

True/False: If you update or delete a record in its before trigger, or delete a record in its after trigger, you will receive a runtime error.

A

True.

28
Q

Given the following scenario: You update account A, and the before update trigger of account A inserts contact B, and the after insert trigger of contact B queries for account A and updates it using the DML update statement or database method.
What will happen?

A

runtime error.

You are indirectly updating account A in its before trigger.

29
Q

Mention 3 ways Apex can be invoked.

A
  1. Anonymous block.
  2. A trigger invoked for specified events.
  3. Asynchronous Apex by executing a future method, scheduling an Apex class to run at specified intervals, or running a batch job.
  4. Apex Web Services, which allow exposing your methods via SOAP and REST Web services.
  5. Apex Email Service to process inbound email.
  6. Visualforce controllers, which contain logic in Apex for Visualforce pages.
  7. The Ajax toolkit to invoke Web service methods implemented in Apex.
30
Q

True/False: To handle incoming emails two tasks must be performed. 1. Create an Apex class that implements an interface for the Emails. 2. Setup and enable the interface through the Email Services Page.

A

True

31
Q

Which interface must be implemented when implementing an inbound email service?

A

Messaging.IndboundEmailHandler

32
Q

What can be the cause of the message: MASS_MAIL_LIMIT_EXCEEDED.

A

The limit is hit either by sending to many emails in one transaction or by sending to many emails during a day.

33
Q

What does the following two methods in the Messaging.sendEmailMessage do:

  1. setDocumentAttachments
  2. setFileAttachments
A

Both are options to add an attachment to emails generated by Apex code.

34
Q

True/False: VisualForce email templates can be used for mass email.

A

False.

35
Q

True/False: Salesforce.com can track the status of emails in HTML format, including when it wass sent, first opened and last opened.

A

True

Note, called Tracking HTML Email

36
Q

What does the following line do:

Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

A

Instantiates an email object for sending a single email message.

37
Q

What does the following line do:

Messaging.MassEmailMessage mail = new Messaging.MassEmailMessage();

A

Instantiates an email object for sending a mass email message.

38
Q

What are the parameters in the following method to send an email:
Messaging.sendEmail(
1 - new messaging.Email[] {mail} ,
2 -opt_allOrNone);

A
  1. Either Messaging.SingleEmailMessage or Messaging.MassEmailMessage.
  2. Specifies whether the operation allows partial success - if false and a record fails, the remainder of the DML operation can still succeed.
    Note, is optional, default is true.
39
Q

True/False: Emails are not sent until the Apex transaction is completed.

A

True

40
Q

True/False: Emails are always sent with the email of the current user as sent by.

A

False.

  1. The users email address can be overwritten using the method: setSenderDisplayName(‘’);
  2. The users email address can be hidden using the method: setUseSignature(false);
41
Q

Dynamic Apex enables developers to create more flexible application by providing them with the ability to do two things, which?

A
  1. Access sObject and field describe information.

2. Write dynamic SOQL or SOSL queries.

42
Q

True/False: sObjects describe information provides information about individual records of an object.

A

False.

It provides information about objects in an organization, not individual records.

43
Q

True/False: The limits methods return the specific limit for the context in which they are being executed.

A

True.

44
Q

There are two versions of Limit methods, describe them.

A
  1. One to return the amount of the resource that has been used in the currec context.
  2. One to return the total amount of the resource that is available for that context.
45
Q

True/False: In the following code the string MsgTxt is not written to the debug log.
System.LoggingLevel level = LogginLevel.ERROR
System.debug(logginlevel.INFO, ‘MsgTxt’);

A

True.
Since the logging level is set to Error, only debug calls with the logginglevel ERROR is shown. However if the logging level was higher, I.E. FINER all debug calls lower than FINER would show in the logs.

46
Q

True/False: During deployment to production, Salesforce enforces the following rules.

  1. 75% of Apex statements must be executed by tests.
  2. Every Apex trigger must be have some test coverage, even though every line of every trigger does not have to be executed by a test.
  3. Every Apex test must execute without throwing any uncaught exceptions or exceeding governors.
A
  1. True
  2. True
  3. True
47
Q

True/False: Cascading delete operations do not cause triggers to execute - records that did not initiate a delete do not cause triggers to execute.

A

True.

48
Q

True/False: All fields can be updated by Triggers

A

False.

createdDate, lastUpdated, Id - some Fields on standard objects.

49
Q

The Trigger Context Variables Old and OldMap can only be used in Insert and Update Triggers.

A

False.

Update and Delete Triggers.

50
Q

What does theTrigger Context Variable Size contain?

A

The total number of records in a trigger invocation, both old and new.

51
Q

What does theTrigger Context Variable isExecuting return?

A

Returns true if the current context for the Apex code is a trigger, not a Visualforce page, a Web service, or an executeanonymous() API call

52
Q

True/False: To Avoid deadlocks first lock parents records, then children.

A

True.

53
Q

True/False: To Avoid deadlocks lock sObject records in order of ID when multiple records of the same type are being edited.

A

True.