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()