- Apex - Deployment
- Apex - Testing
- Apex - Debugging
- Apex - Batch Processing
- Apex - Governer Limits
- Apex - Trigger Design Patterns
- Apex - Triggers
- Apex - Invoking
- Apex - Security
- Apex - SOQL
- Apex - SOSL
- Apex - Database Methods
- Apex - DML
- Apex - Interfaces
- Apex - Objects
- Apex - Methods
- Apex - Classes
- Apex - Collections
- Apex - Loops
- Apex - Decision Making
- Apex - Constants
- Apex - Arrays
- Apex - Strings
- Apex - Variables
- Apex - Data Types
- Apex - Example
- Apex - Environment
- Apex - Overview
- Apex - Home
Apex Useful Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
Apex - Invoking
Apex invoking refers to the process of executing the Apex class. Apex class can only be executed when it is invoked via one of the ways psted below −
Triggers and Anonymous block
A trigger invoked for specified events
Asynchronous Apex
Schedupng an Apex class to run at specified intervals, or running a batch job
Web Services class
Apex Email Service class
Apex Web Services, which allow exposing your methods via SOAP and REST Web services
Visualforce Controllers
Apex Email Service to process inbound email
Invoking Apex Using JavaScript
The Ajax toolkit to invoke Web service methods implemented in Apex
We will now understand a few common ways to invoke Apex.
From Execute Anonymous Block
You can invoke the Apex class via execute anonymous in the Developer Console as shown below −
Step 1 − Open the Developer Console.
Step 2 − Cpck on Debug.
Step 3 − Execute anonymous window will open as shown below. Now, cpck on the Execute button −
Step 4 − Open the Debug Log when it will appear in the Logs pane.
From Trigger
You can call an Apex class from Trigger as well. Triggers are called when a specified event occurs and triggers can call the Apex class when executing.
Following is the sample code that shows how a class gets executed when a Trigger is called.
Example
// Class which will gets called from trigger pubpc without sharing class MyClassWithSharingTrigger { pubpc static Integer executeQuery (List<apex_customer__c> CustomerList) { // perform some logic and operations here Integer ListSize = CustomerList.size(); return ListSize; } } // Trigger Code trigger Customer_After_Insert_Example on APEX_Customer__c (after insert) { System.debug( Trigger is Called and it will call Apex Class ); MyClassWithSharingTrigger.executeQuery(Trigger.new); // Calpng Apex class and // method of an Apex class } // This example is for reference, no need to execute and will have detail look on // triggers later chapters.
From Visualforce Page Controller Code
Apex class can be called from the Visualforce page as well. We can specify the controller or the controller extension and the specified Apex class gets called.
Example
VF Page Code
Apex Class Code (Controller Extension)
Advertisements