Logic and Process Automation: 33% Flashcards
What are the 7 trigger events?
before insert before update before delete after insert after update after delete after undelete
Why would you Bulkifying DML Calls?
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)
Give an example on how to bulkify a for loop
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;
What is the only method of the Schedulable interface?
The only method that the Schedulable interface contains is the execute method
global void executable(SchedulableContext sc) {}
What are the arguments of the System.schedule method?
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 many classes can you schedule at one time (through System.Schedule)
You can only have 100 classes scheduled at one time.
What interface do you need to implement when writing a batch Apex class?
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 { ...
What are the three methods you need to implement when writing a batch Apex class?
- start
- execute
- 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 do you invoke a Batch Class?
Instantiate it first and then call Database.executeBatch with the instance of your batch lass
For example:
BatchClass myBatchObject = new BatchClass();
Database.executeBatch(myBatchObject);
What are 3 use cases on when to use Apex Triggers
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)
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
Interviewers__r
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
Postion__r
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
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();
What are the two ways to insert SOQL statements into Apex
1- Square-bracketed expressions
ex: [ SELECT Name from Position__c]
2- Database.query method:
ex Database.query(‘SELECT ‘ + MyFieldsString + ‘ FROM ACCOUNT’)
What are the three data types that a SOQL statement can return
- List of sObjects
- Single sObject
- Integer
Which SOQL Function will you use to return the average value of a numeric field.
AVG()
Which SOQL Function will you use to return the number of rows matching the query criteria.
COUNT()
Which SOQL Function will you use to return the number of distinct non-null field values?
COUNT_DISTINCT()
Which SOQL Function will you use to return the minimum value of a field
MIN()
Which SOQL Function will you use to return the maximum value of a field
MAX()
Which SOQL Function will you use to return the total sum of a numeric field
SUM()
Which SOQL Function will you use to return a number representing the calendar month of a date field
CALENDAR_MONTH()
Which SOQL Function will you use to return a number representing the day in the month of a date field
DAY_IN_MONTH()
Which SOQL Function will you use to return a number representing the fiscal year of a date field
FISCAL_YEAR()
Which SOQL Function will you use to return a number representing the week in the year for a date field
WEEK_IN_YEAR()
Which exception would be generated if you try an access a field that was not included in the select clause of a SOQL?
System.SObjectException
What keyword should you add to the SOQL query to return both active and deleted records
ALL ROWS
What is the maximum of child-to-parent relationships you can have within a SOQL query
Maximum of 5
What is the maximum of parent-to-child relatioships you can have within a SOQL query
Only one parent-to-child relationship
What is the main difference between SOQL and SOSL?
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.
What is the result of a SOSL query?
Return a list of lists of sObjects
Which fields are excluded when a SOSL query is run?
Dates, IDs and Numbers
Which clause is used in a SOSL query to specify the search string
The FIND clause
ex: List> results = [FIND ‘Acme*’ …];
Which clause is used to limit the type of fields to search in a SOSL query
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 …];
Which clause is used to limit the results to a specified object type in a SOSL query
The RETURNING Clause limits results per sObject type
ex: List> results = [FIND ‘Acme*’ IN NAME FIELDS RETURNING Account, Contact];
Which clause in a SOSL query is used to filter search results on specific field values
the WHERE clause
ex: List> results = [FIND ‘Acme*’ IN NAME FIELDS RETURNING Account(Name, BillingCountry WHERE CreatedDate= THIS_FISCAL_QUARTER)];
What is wrong with the following piece of code:
FOR (Position__c p : [SELECT id FROM Position__c]) {
//code block
Database.update(p);
}
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.
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) 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
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
B) and D). You can insert SOQL into Apex either by enclosing them in square-bracketed expressions or by using the Database.query method
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
B) RETURNING clause is used to limit results to specified object types
In the execution order of triggers, what are the 3 steps that happen before the “before” triggers are executed
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
In the execution order of triggers, what are the 3 steps after the “before” triggers were executed, and before the “after” triggers are executed?
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
What are the two steps after the “after” triggers are executed for the first time?
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
What are the 8 final steps after the “before” and “after” triggers were executed?
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
Which trigger context variable returns the total number of new and old sObjects?
Trigger.size
What does Trigger.new mean?
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
When can Trigger.new values be modified?
Only when used with before triggers
What does Trigger.newMap mean
Trigger context variable that returns a map of IDs for the new versions of the sObjects.
What does Trigger.old mean?
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
What does Trigger.oldMap mean?
Trigger.oldMap is similar to Trigger.old, but returns a map relating the record IDs to sOjbects
How/Why is the addError() method used?
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.
In which context does the triggers run by default?
Run as system by default
Which bulk operations do not execute triggers?
1 - Cascade deletion 2 - Mass campaign 3 - Status updates 4 - Renaming Picklists 5 - Managing price books
Can a trigger contain the static keyword?
No, Trigger code cannot contain the static keyword, and can contain keywords applicable to an inner class.
What is a possible impact of a cascading trigger (trigger that causes other triggers to fire off)
Cascading triggers are considered to be part of the same execution context for governor limits
What triggers will an upsert event cause?
Both insert and update triggers