Apex Flashcards
what is the transient keyword used for?
Use the transient keyword to declare instance variables that can’t be saved, and shouldn’t be transmitted as part of the view state for a Visualforce page.
True or False?
Declaring variables as transient reduces view state size?
True
Which of the following are true regarding custom setting data?
Choose 2
A. Custom setting data can be accessed by formula fields, validation rules, Apex and Visualforce pages
B. There are two types of custom setting data, hierarchy and list
C. Custom setting data needs to be queried once using SOQL and then it is stored in the chache
D. Custom setting data cannot be queried using SOQL
A. Custom setting data can be accessed by formula fields, validation rules, Apex and Visualforce pages
B. There are two types of custom setting data, hierarchy and list
Can before insert change fields using trigger.new?
Yes
Can after insert change fields using trigger.new?
Not allowed.
A runtime error is thrown.
Trigger.new is already saved
Can before update change fields using trigger.new?
Yes
Can after update change fields using trigger.new?
Not allowed.
A runtime error is thrown.
Trigger.new is already saved
Can before delete change fields in trigger.new?
Not allowed. A runtime error is thrown. trigger.new is not available in before delete triggers.
Can after delete change fields in trigger.new?
Not allowed. A runtime error is thrown. trigger.new is not available in after delete triggers.
Can after undelete change fields in trigger.new?
Not allowed. A runtime error is thrown.
Can before insert update original object using an update DML operation?
Not applicable. The original object has not been created; nothing can reference it, so nothing can update it.
Can after insert update original object using an update DML operation?
Yes
Can before update update original object using an update DML operation?
Not allowed. A runtime error is thrown.
Can after update update original object using an update DML operation?
Allowed. Even though bad code could cause an infinite recursion doing this incorrectly, the error would be found by the governor limits.
Can before delete update original object using an update DML operation?
Allowed. The updates are saved before the object is deleted, so if the object is undeleted, the updates become visible.
Can after delete update original object using an update DML operation?
Not applicable. The object has already been deleted.
Can after undelete update original object using an update DML operation?
Allowed
Can before insert delete original object using a delete DML operation
Not applicable. The original object has not been created; nothing can reference it, so nothing can update it.
Can after insert delete original object using a delete DML operation
Allowed, but unnecessary. The object is deleted immediately after being inserted.
Can before update delete original object using a delete DML operation
Not allowed. A runtime error is thrown.
Can after update delete original object using a delete DML operation
Allowed. The updates are saved before the object is deleted, so if the object is undeleted, the updates become visible.
Can before delete delete original object using a delete DML operation
Not allowed. A runtime error is thrown. The deletion is already in progress.
Can after delete delete original object using a delete DML operation
Not applicable. The object has already been deleted.
Can after undelete insert delete original object using a delete DML operation
Allowed, but unnecessary. The object is deleted immediately after being inserted.
What does Limits.getDMLRows() do?
counts the number of records that have been processed with any statement that counts against DML limits
What does Limits.getLimitDMLRows() do?
returns the actual limit of statements that count against DML limits
What is a constructor?
code that is invoked when an object is created from the class blueprint
Does a constructor need to be written for every class?
No
What happens if a class does not have a constructor?
If a class does not have a user-defined constructor, a default, no-argument, public constructor is used.
What does Trigger.old return?
A list of the old versions of the sObject record. Only available in update and delete.
How do triggers prevent DML operations from occurring?
By calling the addError() method on a record or field. A custom error is displayed in the application interface and logged
What is true regarding cascading execution of triggers?
A. Cascading execution of triggers will cause an exception
B. Cascading triggers are part of the same execution context with respect to governor limits
C. Each trigger will start a new execution context
D. There is a limit of 5 triggers that can be executed from a cascading execution
B. Cascading triggers are part of the same execution context with respect to governor limits
How can the relationship between different accounts be recorded and viewed?
Choose 2
A. Using the View Hierarchy link
B. Using the Parent Account field
C. Using the Generate Relationship function
D. Using the Related Account field
A. Using the View Hierarchy link
B. Using the Parent Account field
Which of the following statements are true when defining Apex classes?
Choose 2
A. It is optional to specify an access modifier in declaring inner class B. A top level class can have multiple levels of inner classes C. It is required to specify an access modifier in declaring top level classes D. It is optional to specify an access modifier in declaring a top-level class
A. It is optional to specify an access modifier in declaring inner class
C. It is required to specify an access modifier in declaring top level classes
What does the private access modifier do?
declares that this class is only known locally, that is, only by this section of code.
What is the default access for inner-classes if you don’t specify a modifier?
Private
What does the public access modifier do?
declares that this class is visible in your application or namespace
What does the global access modifier do?
declares that this class is known by all Apex code everywhere. All classes that contain methods defined with the webservice keyword must be declared as global. If a method or inner class is declared as global, the outer, top-level class must also be defined as global.
What does the virtual definition modifier do?
declares that this class allows extension and overrides. You cannot override a method with the override keyword unless the class has been defined as virtual.
What does the abstract definition modifier do?
The abstract definition modifier declares that this class contains abstract methods, that is, methods that only have their signature declared and no body defined.
What does the protected access modifier do?
enables a method to be visible to inner classes of the Apex class it is defined in as well as extensions of the class
Can you use the protected access modifier on static methods?
No.
It is only allowed on instance methods and member variables.
What is an Apex transaction?
Single unit of work when you make a request to Salesforce.
What are governor limits based on?
One Apex transaction
What is true regarding a future method?
Choose 2:
A. Methods that are annotated with @future identify methods that are executed asynchronously.
B. Methods annotated with @future can only return a void type.
C. A method annotated with @future can only return a void type
D. Methods that are annotated with @future identify methods that are executed synchronously
A. Methods that are annotated with @future identify methods that are executed asynchronously.
B. Methods annotated with @future can only return a void type.
When should you use the @future annotation?
to identify methods that are executed asynchronously.
When does a method with @future annotation execute?
When Salesforce has available resources
What is the only return type @future methods can have?
void
What is needed to allow @future methods to callout to external web services?
(callout=true)
What does trigger.new contain?
A list of new versions of records and is available in insert, update, and undelete triggers
As per the order of execution, when will an email created from a workflow email alert be sent?
A. After all DML operations are committed to the database
B. Before entitlement rules execution
C. When all before triggers are executed
D. After workflow rule execution
A. After all DML operations are committed to the database
Which features are available in Visual Studio Code?
Choose 2
A. Process Builder
B. Schema Builder
C. Code Editor
D. Execute Anonymous code
C. Code Editor
D. Execute Anonymous code
Because Apex runs in a multitenant environment, the Apex runtime engine enforces limits to ensure that Apex code or processes don’t monopolize shared resources. What are valid examples of these limits?
Choose 3
A. Time executing a SOQL query
B. Total number of records retrieved by SOQL queries
C. CPU time per transaction
D. Maximum execution time for DML operation
E. Maximum number of records that can be stored?
A. Time executing a SOQL query
B. Total number of records retrieved by SOQL queries
C. CPU time per transaction
A PageReference is a reference to an instantiation of a page. Which of the following are valid means of instantiating a PageReference?
Choose 2
A. PageReference.page(‘URL’)
B. Page.existingPageName
C. ApexPages.Page().existingPageName
D. PageReference pageRef = new PageReference(‘URL’);
B. Page.existingPageName
D. PageReference pageRef = new PageReference(‘URL’);
When should you use Page.existingPageName?
To refer to a PageReference for a Visualforce page that has already been saved in your organization
When should you use PageReference pageRef = new PageReference(‘URL’);
When creating a PageReference to any page that is hosted on the Force.com platform
When should you use PageReference pageRef = ApexPages.currentPage();
When instantiating a PageReference object for the current page
When should you use a PageReference Class?
To view or set query string parameters and values for a page
To navigate the user to a different page as the result of an action method