1/17
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
|---|
No study sessions yet.
Rules when working with databases
RULES:
You cannot perform a callout after doing DML (database operations) in the same transaction. You must separate DML and callout using @future.
@future
A decorator that runs a method later, asynchronously
The new transaction has no uncommited DML and is allowed to make external API callouts
When used:
To make callouts after DML
Separate DML and callouts
Offload long-running work
Keep UI/Triggers fast
Key Rules:
Method must be static
Must return void
Arguments can only be primitive dtypes
Exam Tips
Use on questions about DML / Callout
@InvocableMethod
Method level. Makes a method callable from Flow, Process Builder, or external tools
When Used:
For no-code Flow automation
Integrating Apex with automation tools
Calling Apex from a Flow to perform a task.
Rules:
Must be static
Can only accept single-parameter types supported by Flow (list of primitives or sObjects)
Exam Tips
Use for integration with Flow questions
Database.setSavepoint()
Creates a checkpoint in the current transaction
Database.rollback(savepoint)
rollsback database to the savepoint
@AuraEnabled
Method or Property. Exposes Apex methods or properties to Lightning Components (Aura and LWC)
Rules
Methods must be static to be called from LWC
Can specify cacheable=true to allow client-side caching
Use cases:
Lightning Components calling Apex methods
Lightning Data Service Integrations
Exam Tips
Frequently comes up in Lightning performance and caching questions
@TestMethod / @isTest
Method/Class level. Marks methods or classes as unit tests
Rules
Test methods cannot call future methods directly unless wraped in Test.startTest() / Test.stopTest()
Can be used on both classes and methods
Use Cases
Writing Apex unit tests to satisfy coverage
Testing trigger and controller logic
Exam Tips
PDII focuses heavily on testing best practices
@ReadOnly
Method-level. Allows queries in read-only mode within Visualforce controllers or batch operations
Rules
Cannot perform DML
Increases governor limits for queries
Use Cases
Batch or high-volume query operations
Improving performance when only reading records
Exam Tips
Use for optimization/performance questions
@Schedulable / @Scheduled
Class-level. Allows the class to be scheduled to run at a specific time or interval
Rules
Must implement Schedulable.execute() method
Use Cases
Nightly updates, periodic reporting, data cleanup
@Batchable / @Database.Batchable
Class-level. Marks a class as batch Apex, processing large datasets asynchronously
Rules
Must implement start(), execute(), and finish()
Can be chained with other batch classes
Use Cases
Large data updates or integrations
@Queueable
Method/Class level. Enqueues Apex for asynchronous execution with more flexibility than @future
Rules
Implements Queueable interface
Can chain jobs
Supports complex objects as parameters (unlike @future)
Use Cases
Async callouts with complex objects
Background processing in trigger
@Deprecated
Method/Class. Marks a method or class as deprecated, signaling that it should not be used in future development
Use Cases
Legacy code maintenance
@InvocableVariable
Property-level. Works with @InvocableMethod to expose input/output variables for Flow or Process Builder
Use Cases
Define what a Flow is can pass to Apex
Define what Apex returns to Flow
@TestSetup
Method level. Sets up common test data that can be reused across multiple test methods in a class.
Use Cases
Reduces code deuplication in tests
Improves test performance
@Storable
@SeeAllData
Method-level. allows test methods to access org data instead of creating mock records
Use Cases
Quick testing without creating test records
@RestResource
Class Level. Exposes an Apex class as a REST API endpoint
Use Cases
Create RESTful web services for external systems
@HttpGet / @HttpPost / @HttpPut / @HttpDelete
Method-level REST. Designates a method as handling a specific HTTP verb for a REST class
Use Cases
Implement REST endpoints for CRUD operations