Asynchronous Apex Flashcards

1
Q

What is asynchronous apex?

A

It allows us to call a function and continue execution of the calling code while we wait for the function to complete so this allows parallel processing

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

How do implement Asynchronous Apex?

A
  1. @future annotation
  2. Queueable interface
  3. Database.Batchable interface
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the difference between @future and queueable?

A
  • Future
    • Parameters need to be primitive
    • cannot chain
  • Queueable
    • Parameters can be non-primitive (sObject or custom Apex Type)
    • can chain up to one job
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What methods must be included when writing a Batch class?

A

Start - used to collect records or object passed to interface method “execute” for processing

  • Will return either a Database.QueryLocator object or a list of records/objects
  • Governor limit
    1. GL for QueryLocator is bypassed and can go up to 50mil
    2. Whereas returning a list of objects is still 50,000.

Execute - performs the actual processing of “batch” of data.

  1. Takes in:
    1. A reference to the Database.BatchableContext object.
    2. A list of sObjects

Finish - used to execute post-processing operation (i.e. send email) and is called once all batches are processed

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

What is the order of Cron Expression?

A

Seconds 0-59

Minutes 0-59

Hour 0-24

Day of Month 1-31

Month 1-12

Day of Week 1-7

Year YYYY

* = Select all values

? = no specific value

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

What would this translate too 0 0 12 * * ?

A

Fire at 12PM every day

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

What is a Future Method?

A

Run in their own thread, and do not start until resources are available.

Typically used or callouts to external web services

@future annotation is added to the beginning of a static method

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

What is Queueable Apex?

A

Similar to future methods, but provide additional job chaining and allow more complex data types to be used.

  1. ID - we can use to track it’s execution
  2. Can contain member variables of non-primitive type
    1. sObjects or custom Apex type
  3. Can chain one job to another job

You can add jobs to the queue with System.enqueueJob();

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

When would you use Batch Apex?

A

Run large jobs that would exceed normal processing limits.

data caleansing or archiving records

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

When would you use Scheduled Apex?

A

When you want it to run at a specified time.

Daily or weekly tasks.

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