Logic and Process Automation: 33% Flashcards

1
Q

What are the 7 trigger events?

A
before insert
before update
before delete
after insert
after update
after delete
after undelete
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why would you Bulkifying DML Calls?

A

Making DML calls on lists of sObjects instead of each individual sObject makes it less likely to reach the DML statements limit (150 DML statements per transaction)

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

Give an example on how to bulkify a for loop

A
Instead of:
for(Line_Item\_\_c li : liList) {
    if (li.Units_Sold\_\_c > 10) {
        li.Description\_\_c = 'New description';
    }
    // Not a good practice since governor limits might be hit.
    update li;
}
Write it as : 
List updatedList = new List();
for(Line_Item\_\_c li : liList) {
    if (li.Units_Sold\_\_c > 10) {
        li.Description\_\_c = 'New description';
        updatedList.add(li);
    }
}
// Once DML call for the entire list of line items
update updatedList;
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is the only method of the Schedulable interface?

A

The only method that the Schedulable interface contains is the execute method
global void executable(SchedulableContext sc) {}

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

What are the arguments of the System.schedule method?

A

The System.Schedule method takes 3 arguments: a name for the job, an expression used to represent the time and date the job is scheduled to run, and the name of the class.

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

How many classes can you schedule at one time (through System.Schedule)

A

You can only have 100 classes scheduled at one time.

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

What interface do you need to implement when writing a batch Apex class?

A

Your class must implement the Database.Batchable interface. Your class declaration must include the implements keyword followed by Database.Batchable

For example:
global class CleanUpRecords implements Database.Batchable { ...
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What are the three methods you need to implement when writing a batch Apex class?

A
  1. start
  2. execute
  3. finish

start method:
global (Database.QueryLocator | Iterable) start(Database.BatchableContext bc) {}

execute method:
global void execute(Database.BatchableContext BC, list<p>){}

finish method:
global void finish(Database.BatchableContext BC){}</p>

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

How do you invoke a Batch Class?

A

Instantiate it first and then call Database.executeBatch with the instance of your batch lass

For example:
BatchClass myBatchObject = new BatchClass();
Database.executeBatch(myBatchObject);

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

What are 3 use cases on when to use Apex Triggers

A

1- Data-Driven Sharing (Apex triggers automate record sharing based on dynamic data-driven record criteria

2- Complex Validation Rule (ex: execute validation logic upon record deletion, or utilize complex database queries to verify data quality)

3- Callout to an External Web Service (Reuse existing interfaces in an enterprise)

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

If the parent object is called Position__c and the child object is called Interviewer__c, please provide the syntax for the parent-to-child relationship

A

Interviewers__r

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

If the parent object is called Position__c and the child object is called Interviewer__c, please provide the syntax for the child-to-parent relationship

A

Postion__r

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

What are the two member variables on the child object to refer to the parent. For example, if the Parent Object called Position and the child object is called Job Application

A

1 - Using the foreign key
ex:
Job_Application__c ja1 = new Job_Application__c();
ja1.position__c = ‘a05S0000000WZeYIAW’

2 - Using the object reference
ex:
Job_Application__c ja1 = new Job_Application__c();
ja1.position__r = new Position__c();

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

What are the two ways to insert SOQL statements into Apex

A

1- Square-bracketed expressions
ex: [ SELECT Name from Position__c]

2- Database.query method:
ex Database.query(‘SELECT ‘ + MyFieldsString + ‘ FROM ACCOUNT’)

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

What are the three data types that a SOQL statement can return

A
  1. List of sObjects
  2. Single sObject
  3. Integer
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

Which SOQL Function will you use to return the average value of a numeric field.

A

AVG()

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

Which SOQL Function will you use to return the number of rows matching the query criteria.

A

COUNT()

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

Which SOQL Function will you use to return the number of distinct non-null field values?

A

COUNT_DISTINCT()

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

Which SOQL Function will you use to return the minimum value of a field

A

MIN()

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

Which SOQL Function will you use to return the maximum value of a field

A

MAX()

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

Which SOQL Function will you use to return the total sum of a numeric field

A

SUM()

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

Which SOQL Function will you use to return a number representing the calendar month of a date field

A

CALENDAR_MONTH()

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

Which SOQL Function will you use to return a number representing the day in the month of a date field

A

DAY_IN_MONTH()

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

Which SOQL Function will you use to return a number representing the fiscal year of a date field

A

FISCAL_YEAR()

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

Which SOQL Function will you use to return a number representing the week in the year for a date field

A

WEEK_IN_YEAR()

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

Which exception would be generated if you try an access a field that was not included in the select clause of a SOQL?

A

System.SObjectException

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

What keyword should you add to the SOQL query to return both active and deleted records

A

ALL ROWS

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

What is the maximum of child-to-parent relationships you can have within a SOQL query

A

Maximum of 5

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

What is the maximum of parent-to-child relatioships you can have within a SOQL query

A

Only one parent-to-child relationship

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

What is the main difference between SOQL and SOSL?

A

SOQL is used to construct simple but powerful query strings in APex.

SOSL is used to search for specific data in your org. Unlike SOQL, SOSL can query multiple objects at once and is used to perform text searches.

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

What is the result of a SOSL query?

A

Return a list of lists of sObjects

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

Which fields are excluded when a SOSL query is run?

A

Dates, IDs and Numbers

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

Which clause is used in a SOSL query to specify the search string

A

The FIND clause

ex: List> results = [FIND ‘Acme*’ …];

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

Which clause is used to limit the type of fields to search in a SOSL query

A

The IN Clause specifies the following search scope:

  • ALL FIELDS
  • EMAIL FIELDS
  • NAME FIELDS
  • PHONE FIELDS
  • SIDEBAR FIELDS
    ex: List> results = [FIND ‘Acme*’ IN NAME FIELDS …];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
35
Q

Which clause is used to limit the results to a specified object type in a SOSL query

A

The RETURNING Clause limits results per sObject type

ex: List> results = [FIND ‘Acme*’ IN NAME FIELDS RETURNING Account, Contact];

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

Which clause in a SOSL query is used to filter search results on specific field values

A

the WHERE clause
ex: List> results = [FIND ‘Acme*’ IN NAME FIELDS RETURNING Account(Name, BillingCountry WHERE CreatedDate= THIS_FISCAL_QUARTER)];

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

What is wrong with the following piece of code:
FOR (Position__c p : [SELECT id FROM Position__c]) {
//code block
Database.update(p);
}

A

In this example, the DML statement is executed inside the loop, which results in one DML call for each sObject record. This pattern will break if the number of DML statements exceed the limit of 150.

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

Which of the following statements are true about a SOQL SELECT statement? (Choose all that apply)
A) It is similiar to the SELECT statement in SQL
B) It is used to perform searches across multiple sObjects
C) It helps retrieve records from an object in the Force.com database
D) It returns a list of lists of sObjects

A

A) and C). The SOQL SELECT statement is similar to the SELECT statement in SQL and includes a list of fields to retrieve records from an object in the Force.com database

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
39
Q
What are the two ways to insert SOQL into Apex?
A) Database.search() method
B) Square-bracketed expressions
C) search() method
D) Database.query() method
A

B) and D). You can insert SOQL into Apex either by enclosing them in square-bracketed expressions or by using the Database.query method

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
40
Q
Identify the clause that is used in a SOSL statement to limit results to specified object types:
A) IN
B) RETURNING
C) WHERE
D) ORDER BY
A

B) RETURNING clause is used to limit results to specified object types

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

In the execution order of triggers, what are the 3 steps that happen before the “before” triggers are executed

A

1 - The original record is loaded from the database or initialized for insert
2 - The new record field values are loaded and old values are overwritten
3 - System validation rules are executed and required fields are verified

Before triggers are executed

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

In the execution order of triggers, what are the 3 steps after the “before” triggers were executed, and before the “after” triggers are executed?

A

Before triggers were executed

1 - Most system validation steps are run again and validation rules are checked
2 - Executes duplicate rules
3 - The record is saved to the database but not committed

After triggers are executed

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

What are the two steps after the “after” triggers are executed for the first time?

A

After triggers were executed

1 - Assignment rules, auto-response rules, and workflow rules are executed
2 - Records are updated again if workflow fields are updated

Before and After triggers are executed again if fields are updated based on workflow rules
Standard validations are checked. BUT Custom validation rules, duplicate rules and escalation rules are NOT run again

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

What are the 8 final steps after the “before” and “after” triggers were executed?

A

1 - Executes processes (if there are worfklow flow triggers the flows are executed)
2 - Escalation rules are executed
3 - Executes entitlement rules
4 - Rollup summary formula or cross-object formula fields are updated in the parent records and affected records are saved
5 - Repeat the same process for affected grand parent records
6 - Criteria Based Sharing evaluation is executed
7 - All DML operations are committed to the database
8 - Post-commit logic is executed

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

Which trigger context variable returns the total number of new and old sObjects?

A

Trigger.size

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

What does Trigger.new mean?

A

Trigger context variable that returns a list of new versions of the sObjects.
Can be used in insert and update triggers.
Contains references to sObjects

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

When can Trigger.new values be modified?

A

Only when used with before triggers

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

What does Trigger.newMap mean

A

Trigger context variable that returns a map of IDs for the new versions of the sObjects.

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

What does Trigger.old mean?

A

Contains the references to the current version of sObjects. It is used only in update and delete triggers

And it is READ ONLY
In the context of an insert operation it is NULL

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

What does Trigger.oldMap mean?

A

Trigger.oldMap is similar to Trigger.old, but returns a map relating the record IDs to sOjbects

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

How/Why is the addError() method used?

A

The addError() method :

  • helps prevent the completion of DML operations for the marked records
  • Can be applied to the sObject or to a specific field
  • Can cause error messages to appear in the Salesforce UI

For instance, if a record save is issued and the record contains bad data, the addError method can prevent the record from being saved and then issue a warning about the bad data to the user.

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

In which context does the triggers run by default?

A

Run as system by default

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

Which bulk operations do not execute triggers?

A
1 - Cascade deletion
2 - Mass campaign
3 - Status updates
4 - Renaming Picklists
5 - Managing price books
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
54
Q

Can a trigger contain the static keyword?

A

No, Trigger code cannot contain the static keyword, and can contain keywords applicable to an inner class.

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

What is a possible impact of a cascading trigger (trigger that causes other triggers to fire off)

A

Cascading triggers are considered to be part of the same execution context for governor limits

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

What triggers will an upsert event cause?

A

Both insert and update triggers

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

What triggers will a merge event cause?

A
  • Delete triggers for the unsuccessful records

- Update triggers for the successful records

58
Q

What are the only records that an after undelete trigger will work on?

A

The after undelete trigger works only with recovered records.
In addition, undelete events run only on top -level objects.

59
Q

What is Apex Sharing?

A
  • Apex sharing is a way to create custom sharing reasons and control access levels for those reasons using custom Apex Scripts
  • Custom Apex sharing reasons can be created only on custom objects from a custom object configuration menu
60
Q

What is the maximum number of records that a trigger can execute at a time

A

Triggers can execute a maximum of 200 records at a time.

If the number of records exceeds 200, triggers are executed in chunks of 200

61
Q

Identify the best solution (Declarative or Programmatic) to accomplish the following task:

Prevent Duplicate candidate records from being captured in the database. The combination of a candidate’s last name and email address is enough to ensure uniqueness within the system.

A

Answer: Declarative!

Declarative solution:

  • Create a unique field on the candidate object
  • Create a workflow rule on the Candidate object
  • Add a workflow action to update the new field
  • Activate the workflow rule

Programmatic Method

  • Create insert or update trigger on Candidate
  • Trigger receives new candidate batch and passes it to the class
  • Class checks the Candidate object for uniqueness
62
Q

Identify the best solution (Declarative or Programmatic) to accomplish the following task:

Ensure that each position object has, at most, one related salary record and that records that violate this rule are prevented from being saved

A

Answer: Declarative!

Declarative solution:

  • Create a unique text field on the Salary object
  • Create a workflow rule on Salary
  • Add a workflow action
  • Activate the workflow rule

Programmatic Method:

  • Create an insert, update or undelete trigger on Salary
  • Trigger receives new salary batch to check for duplicate records
63
Q

Identify the best solution (Declarative or Programmatic) to accomplish the following task:

When a job has been offered to a candidate, the Job application record should be updated accordingly. SO, when a new offer record is created, the Job application should be set with Stage=Offer Extended and Status= Hold.

A

Answer: Programmatic!

Declarative solution:

  • Change the fundamental relationship between Job Application and Offer
  • Add a roll-up summary field
  • Create a workflow rule on Job Application
  • Add two field update actions

Programmatic Method:

  • Create a trigger on Offer
  • Trigger update the value of Stage and Status field to Offer Extended and Hold respectively
64
Q

True or False: The before trigger can be used to access system-updated field values and affect changes in other records

A

False: The after trigger is used to access system-updated field values and affect changes in other records.

65
Q
How many times will a trigger execute for 1,001 records
A) 5
B) 6
C) 10
D) 11
A

B) - 6 times for 1001 records

66
Q

What is the limit of messages that all email services combined can be processed daily?

A

Total number of messages that all email service put together can process in a day is calculated by multiplying the number of user licenses by 1000.

Messages that exceed this limit are bounced, discarded, or queued, based on how the failure response settings for each email service are configured

67
Q

What are the steps to setup an Inbound Email Service

A
1- Create the email handler class shell
2- Configure an email service
3- Complete the email handler class
4- Configure failure response settings
5- Generate service email addresses
6- Activate service email addresses
7- Test inbound email
68
Q

Which Interface should be implemented when creating the Apex email handler class?

A

Messaging.InboundEmailHandler

69
Q

What information do Email Logs contain and how long is it stored?

A

This information is archived for a period for 30 days.

Email logs contain:

  • the email addresses of senders and recipients
  • the date and time an email is sent, the delivery status of each email
  • any error code associated with each email
70
Q

Which method is used to send emails via Apex

A

The Messaging.sendEmail method is used to send emails

71
Q

How many sendEmail methods are allowed in each context?

A

No more than 10 sendEmail methods are allowed in each context.

72
Q

What error is received when the daily mass mail limit has been reached?

A

MASS_MAIL_LIMIT_EXCEEDED

73
Q

What is the daily email limit for overall organization workflow?

A

2 million

74
Q

How many emails can be sent to external email addresses per day?

A

No more than 1000 emails can be sent to external email addresses per day

75
Q

What is the limit to the number of internal emails received?

A

There is no limit to the number of internal emails received in a day.

76
Q

Emails from Salesforce can be configured to automatically comply with which 2 email security frameworks

A

SPF

SenderID

77
Q

What is the SPF security framework?

A

SPF modifies the From address of an inbound email to a salesforce.com email address to verify the legitimacy of an email

78
Q

What is SenderID compliance?

A

SenderID compliance is to automatically populate the Sender field of every email sent from Salesforce with no-reply@salesforce.com

The SenderID compliance enables the receiving mail servers to verify the sender of an email

79
Q

Identify the true statements about email messages
A) You can restrict the domains from which an email service can receive emails
B) Inbound email service allows binary attachments only
C) Emails sent using Apex to internal Salesforce users count against the org email limits for the day
D) You can use email templates to send mass emails to users
E) Multiple email addresses can be generated per service

A

A and E
You can restrict the domains from which an email service can receive emails

Multiple email addresses can be generated per service.

80
Q

What does the Schema Describe component do?

A
  • A way to programatically learn about the metadata of the data model with Apex
  • Calls provide the ability to programatically discover information about the current org schema
81
Q

What is Dynamic SOQL?

A
  • Refers to creation of a SOQL string at runtime within Apex
  • Allows you to query data without hardcoding names of fields and objects in the SOQL statement
  • Makes an application more flexible by allowing SOQL creation at runtime
82
Q

What is Dynamic SOSL

A
  • Refers to creation of a SOSL string at runtime
  • Allows you to search for data without hardcoding names of fields and objects in the SOSL statement
  • Makes an application more flexible by allowing SOSL creation at runtime
83
Q

What is Dynamic DML

A

Provides the ability to perform DML operations on sObjects dynamically

84
Q

What is a token?

A

A token is a type of data structure used for SObject and field describe information.

Specifically it is a lightweight reference to an sObject or a field. It can be compared using the equality operation (==)

85
Q

What describe result object is returned when calling the getDescribe() call from an sObject token?

A

Schema.DescribeSObjectResult

86
Q

What describe result object is returned when calling the getDescribe() call from a field token?

A

Schema.DescribeFieldResult

87
Q

What describe result object is returned when calling the getDescribe() call from an instance of Schema.DescribeSOjbectResult object

A

Schema.ChildRelationship

Schema.RecordTypeInfo

88
Q

What describe result object is returned when calling the getDescribe() call from an instance of a Schema.DescribeFieldResult object

A

Schema.PickListEntry

89
Q

Set the following schemaMap property equal to the Map of SObjectTypes in the current org

private Map schemaMap();
schemaMap = _______________;

A

schemaMap=Schema.getGlobalDescribe();

90
Q

Which of the following statements are true about components of dynamic Apex?

A) Schema describe is a way to programmatically learn about the metadata of your data model within Apex
B) Dynamic SOQL refers to the creation of a SOQL string before runtime within an Apex script
C) In dynamic SOQL, you can use the escapeSingleQuotes method to prevent the SOQL injection
D) You can use dynamic SOSL to create a tree structure of all the objects and fields in your schema browser

A

A) and C)

91
Q

Sequence the steps to execute a code that generates schema describe:
A) Generate a list or map of tokens for the sObjects in your organization
B) Generate a map of field tokens for the sObject
C) Generate the describe result for the sObject
D) Determine the sObject you need to access
E) Generate the describe result for the field the script needs to access

A
  1. Generate a list or map of tokesn for the sObjects in your organization (A)
  2. Determine the sObject you need to access (D)
  3. Generate the describe result for the sObject (C)
  4. Generate a map of field tokens for the sObject (B)
  5. Generate the describe result for the field the script needs to access (E)
92
Q

What is a key benefit of asynchronous processing?
A) Higher governor and execution limits
B) Unlimited number of external callouts
C) Override organization-wide sharing defaults
D) Enabling turbo mode for transactional processing

A

A) Higher governor and execution limits

93
Q

Batch Apex is typically the best type of asynchronous processing when you want to:
A) Make a callout to a web service when a user updates a record
B) Schedule a task to run on a weekly basis
C) Update all records in your org
D) Send a rickroll email to a contact?

A

C) Update all records in your org

94
Q
What type of jobs do not show up in the Apex Flex Queue?
A) Future Method Jobs
B) Batch Apex Jobs
C) Queueable Apex Jobs
D) Scheduled Apex Jobs
A

A) Future Method Jobs are not showing up currently in the Flex Queue

95
Q

Which statement is true regarding the Flex Queue?
A) You can submit up to 200 batch jobs for execution
B) Jobs are processed first-in first-out
C) Jobs can only be scheduled during Taco Tuesdays
D) Jobs are executed depending upon user license

A

B) Jobs are processed first-in first-out

Please note that Flex enables you to submit up to 100 batch jobs for execution

96
Q

Which tool would you use for the following use case?
Launch a troubleshooting wizard from a button, at the end of which a knowledge article is created if it’d be helpful to other users.

A) Process Builder
B) Visual Workflow
C) Workflow
D) Approvals

A

B) Visual Workflow

97
Q

Which tool would you use for the following use case?
When an opportunity has a discount of more than 40%, notify the CEO via email and request sign-off. Provide a way for the CEO to leave comments.

A) Process Builder
B) Visual Workflow
C) Workflow
D) Approvals

A

D) Approvals

98
Q

Which tool would you use for the following use case?
When an opportunity closes, automatically close all activities related to that opportunity and create a renewal opportunity.

A) Process Builder
B) Visual Workflow
C) Workflow
D) Approvals

A

A) Process Builder

99
Q

Which tool would you use for the following use case?
As an account’s expiration approaches, send recurring email notifications to the owner (2 weeks before, 1 week before, 3 days before, and 1 day before).

A) Process Builder
B) Visual Workflow
C) Workflow
D) Approvals

A

C) Workflow

100
Q

For Asynchronous Apex, give a high overview of Future Methods (and a common scenario)

A

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

Common Scenario: Web service callout.

101
Q

For Asynchronous Apex, give a high overview of Batch Apex (and a common scenario)

A

Overview: Run large jobs that would exceed normal processing limits.

Common Scenario:Data cleansing or archiving of records.

102
Q

For Asynchronous Apex, give a high overview of Queueable Apex (and a common scenario)

A

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

Common Scenario: Performing sequential processing operations with external Web services.

103
Q

For Asynchronous Apex, give a high overview of Scheduled Apex (and a common scenario)

A

Overview: Schedule Apex to run at a specified time.

Common Scenario: Daily or weekly tasks

104
Q

When can a DmlException occur?

A

When there is any problem with a DML statement, such as an insert statement missing a required field on a record

105
Q

What is a ListException?

A

Any problem with a list, such as attempting to access an index that is out of bounds

106
Q

What is a NullPointerException?

A

Any problem with dereferencing a null variable. For example, if you create a string variable named s but don’t initialize it to a value (so it is null), calling the contains method on the null variable causes a NullPointerException

107
Q

What is a QueryException?

A

Any problem with SOQL queries such as assigning a query that returns no records or more than one recordto a singleton sObject variable

108
Q

What error will be thrown by the following piece of code?

String s;
Boolean b = s.contains('abc');
A

NullPointerException

109
Q

What error will be thrown by the following piece of code:

List li = new List ();
Integer i1= li[0]
Integer i2=li[1];

A

ListException

110
Q

What error will be thrown by the following piece of code?

List lm= [SELECT Name FROM Merchandise__c WHERE Name=’XYZ’];

A

QueryException

111
Q

What is an SObjectException

A

Any problem with sObject records, such as attempting to change a field in an update statement that can only be changed during insert

112
Q

What error will be thrown by the following piece of code?

Invoice_Statement\_\_c inv = new Invoice_Statement\_\_c(
        Description\_\_c='New Invoice');
insert inv;

Invoice_Statement__c v = [SELECT Name FROM Merchandise__c WHERE Id=:inv:Id];
String s = v.Description__c;

A

SOjbectException (because the description field was not retrieved)

113
Q

What is the Synchronous and Asynchronous limit for the total number of SOQL queries issued in a single apex transaction?

A

Synchronous: 100
Asynchronous: 200

114
Q

What is the limit of the total number of records retrieved by SOQL queries?

A

50,000

115
Q

What is the limit of the total number of records retrieved by Database.getQueryLocator?

A

10,000

116
Q

What is the total number of SOSL queries issued limit?

A

20

117
Q

What is the total number of records retrieved by a single SOSL query?

A

2000

118
Q

What is the total number of DML statements issued per apex transaction?

A

150

119
Q

What is the total stack depth for any Apex invocation that recursively fires triggers due to insert, update or delete statements

A

16

120
Q

What is the Total number of callouts (HTTP requests or Web service calls) in a transaction?

A

100

121
Q

What is the Maximum timeout for all callouts (HTTP requests or Web services calls) in a transaction?

A

120 seconds

122
Q

What is the maximum number of methods with the future annotation allowed per Apex invocation?

A

50

123
Q

What is the Total number of sendEmail methods allowed?

A

10

124
Q

What is the Synchronous and Asynchronous limits for the total Heap size?

A

Synchronous: 6MB
Asynchronous: 12MB

125
Q

How can you rewrite the following piece of code to make it more efficient if it is to be called multiple times:

Account refAcct = [SELECT Id FROM Account WHERE externalId__c=’12345’];

Contact c = new Contact(Account = refAcct.Id);

insert c;

A

Remove the SOQL query and replace it as follows:

Account refAcct = new Account(externalId__c = ‘12345’);

Contact c = new Contact(Account = refAcct, LastName = ‘Kay’);

insert c;

126
Q

Which Asynchronous Apex Feature should you use for the following?

  • When you have a long-running method and need to prevent delaying an Apex transaction
  • When you make callouts to external Web services
  • To segregate DML operations and bypass the mixed save DML error
A

Future Mehtods

127
Q

Which Asynchronous Apex Feature should you use for the following?

  • To start a long-running operation and get an ID for it
  • To pass complex types to a job
  • To chain jobs
A

Queueable Apex

128
Q

Which Asynchronous Apex Feature should you use for the following?

  • For long-running jobs with large data volumes that need to be performed in batches, such as database maintenance jobs
  • For jobs that need larger query results than regular transactions allow
A

Batch Apex

129
Q

Which Asynchronous Apex Feature should you use for the following?

To schedule an Apex class to run on a specific schedule

A

Scheduled Apex

130
Q

Name 2-4 Future Method Performance Best Practices

A
  • Avoid adding large numbers of future methods to the asynchronous queue
  • Ensure that future methods execute as fast as possible
  • Test your future methods at scale
  • Consider using batch Apex instead of future methods to process large numbers of records
131
Q

Name 2-3 Apex Scheduler Best Practises

A
  • Use extreme care if you’re planning to schedule a class from a trigger.
  • Though it’s possible to do additional processing in the execute method, we recommend that all processing take place in a separate class.
  • Synchronous Web service callouts are not supported from scheduled Apex.
132
Q

Name 4-6 Batch Apex best practices

A
  • Use extreme care if you’re planning to schedule a class from a trigger.
  • Use Database.Stateful with the class definition if you want to share instance member variables or data across job transactions.
  • Methods declared as future aren’t allowed in classes that implement the Database.Batchable interface.
  • Methods declared as future can’t be called from a batch Apex class
  • All methods in the class must be defined as global or public.
133
Q

What happens if you set more than one savepoint and roll back to the first savepoint and then try and roll back to the second savepoint that was set?

A

The later savepoint variables become invalid. For example, if you generated savepoint SP1 first, savepoint SP2 after that, and then you rolled back to SP1, the variable SP2 would no longer be valid. You will receive a runtime error if you try to use it.

134
Q

Can you declare a savepoint as a static variable and use it across trigger contexts?

A

No, you will receive a run-time error

135
Q

What happens to static variables during a rollback?

A

Static variables are not reverted during a rollback. If you try to run the trigger again, the static variables retain the values from the first run.

136
Q

Which governor limit does the rollback count against?

A

Each rollback counts against the governor limit for DML statements. You will receive a runtime error if you try to rollback the database additional times.

137
Q

When using rollbacks, what is the impact of inserting an object before the rollback?

A

The ID on an sObject inserted after setting a savepoint is not cleared after a rollback. Create an sObject to insert after a rollback. Attempting to insert the sObject using the variable created before the rollback fails because the sObject variable has an ID. Updating or upserting the sObject using the same variable also fails because the sObject is not in the database and, thus, cannot be updated.

138
Q

How can you perform DML operations on more than one type of sObject in a single class?

A
  1. Create a method that performs a DML operation on one type of sObject.
  2. Create a second method that uses the future annotation to manipulate a second sObject type.
139
Q

If updating a user in a transaction with other sObjects in Apex Code .. which fields should you NOT also update to avoid getting a MIXED DML error message?

A

You can update a user in a transaction with other sObjects in Apex code saved using Salesforce API version 15.0 and later if the following fields are not also updated:

  • UserRoleId
  • IsActive
  • ForecastEnabled
  • IsPortalEnabled
  • Username
  • ProfileId
140
Q

What syntax do you use in Apex to reference a custom label?

A

System.Label.Label_name

141
Q

What syntax do you use in Visualforce and Lightning components to reference a custom label?

A

$Label.Label_name

142
Q

What is the Namespace for Chatter in Apex?

A

The ConnectApi namespace (also called Chatter in Apex) provides classes for accessing the same data available in Chatter REST API. Use Chatter in Apex to create custom Chatter experiences in Salesforce.