Apex is a strongly typed, object-oriented programming language that allows developers to execute flow and transaction control statements on the Force.com platform server in association with calls to the Force.com API. As a language Apex is an Integrated, easy-to-use, rigorous, multi-tenant aware, upgradeable, easy to test, and versioned. Apex Code can be initiated by Web service requests and from triggers on objects.
Apex is of generally two types:
Schedulable APEX:
Schedulable:- There is an interface in the apex which is schedulable
Limitations:
Eg:
Schedulable {
Void executes (schedulable context sc)
}
Class time bomb implements schedulable {
Void executes (schedulable context SC) {
System.debug (‘ I love you Pandu’);
} ↓
} to perform DB operations here
Batchable Apex:
Batch Apex operates over small batches of records, covering your entire record set and breaking the process down into manageable chunks.
An interface is nothing but a class in which the method signatures are present, but the body of the method is absent. Following are the methods of an interface:
Collect the data first
A group of values that we can apply is Iterable
Maximum number of values → 50,000
It has a capacity of a maximum of 50 million records
As the data begin from the start and logic here is performed on the data
Void executes (batch able content BC, list < S object >)
→ Void finish (batchable content DC)
→ The return type is void
Ex:
Global class BA_ test implements data base < subject > database stateful
{
String one_name = ‘Krishna’;
Global iterable start (database batch able context bc)
{
List BL = new list ();
One_name = ‘Ashok’;
BL = « ______ »;
CA → alias name to book_c)
Return bl;
}
Global void execute (database.batchable connext BC, list < book _ c > BL)
}
Since (book _ c b: BL )
{
System. Debug (‘book name:’ +b.name);
}
For (book_c b: bl)
{
If (b. name ==’ chemistry’)
{
b. price = c = 200;
b. name = ‘physics’;
b. author = c = one_name;
}
}
Try {
Upset BL;
}
Catch (Dml Exception e ) {
Syatem.debug (‘unable to process books ‘);
}
For (book _c b:BL)
{
System.debug (‘book name:’ +b.name);
}
}
Global void finish (database.batch able content BC)
{
System.debug (‘updated chemistry books data is’);
}
Public static test method void main ()
{
BA_test bt = new BA_test ();
ID Jobid = database. executes batch (bt,50);
}
Related Article: Salesforce Interview Questions and Answers |
To execute batch apex we must create a test method
→ There is a special method database. executes batch, which takes two parameters
→ This method is called inside the test method only
Syntax:-
Trigger trigger name on object name (trigger_events){
Code_block
}
There are two types of triggers
After
Insert Insert
Update Update
Delete Delete
Update
→ Go to objects
→ The select object for which you are going to create triggers
Ex: student
→ Go to down the properties of student
→ Triggers —> New
Related Article: SalesForce Tutorial for Beginners |
The context variables provide runtime information about the trigger & the database, these variables are
1. Is executing: It returns true if the trigger is under execution, else false
2. Trigger. Is before: Returns true if this trigger has been fixed way before any record was saved
3. Trigger. Is after: Returns true if this trigger has been fixed after all records were saved
4. Trigger. is insert: Returns true if this trigger has been fixed due to an insert operation, available from the Salesforce user interface, Apex, or the API
5. Trigger. Is update: Returns true if this trigger was fixed due to an update operation, from the Salesforce user interface, Apex, or the API
6. Trigger. Is delete: Returns true if this trigger was fixed due to a delete operation, from the Salesforce apex, or the API
7. Trigger. Is UN delete: Returns true if this trigger was fixed after a record is recovered from the recycle bin
8. Trigger. New:
9. Trigger. OLD:
10. Trigger. New Map:
11. Trigger. Old map:
→ A map of IDS to the old versions of the S object records
→ Note that this map is only available in ‘update & delete’ triggers
→ Trigger. New is holding your object record data which is being currently set by user and trigger. Old contains the history of object records
Eg:
Trigger t1 on food_c (before insert) {
Last < food_c> fc = trigger. New ;
For (food_c f:fc)
{
If (f. price_c <300)
{
f. add error (‘do not eat too much’);
}
}
}
Eg:
Trigger t1 on student_c (before insert, after insert, before update, after update) {
→ List < student_c> b= trigger. New
For (student_c S : b) {
If (S. name_c == ‘harishnath’) {
S. add error (‘do not allow this student’);
}
}
}
Dml Statements:
Related Articles:
An Overview of SalesForce Security
An Introduction to Visualforce – SalesForce
Access Specifiers in SalesForce Cloud Computing - Salesforce
Mindmajix offers different Salesforce certification training according to your desire with hands-on experience on Salesforce concepts
Our work-support plans provide precise options as per your project tasks. Whether you are a newbie or an experienced professional seeking assistance in completing project tasks, we are here with the following plans to meet your custom needs:
Name | Dates | |
---|---|---|
Salesforce Training | Dec 21 to Jan 05 | View Details |
Salesforce Training | Dec 24 to Jan 08 | View Details |
Salesforce Training | Dec 28 to Jan 12 | View Details |
Salesforce Training | Dec 31 to Jan 15 | View Details |
Arogyalokesh is a Technical Content Writer and manages content creation on various IT platforms at Mindmajix. He is dedicated to creating useful and engaging content on Salesforce, Blockchain, Docker, SQL Server, Tangle, Jira, and few other technologies. Get in touch with him on LinkedIn and Twitter.