 Hello. Hi, everyone. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So this is day 44 of Salesforce Learning Bootcamp. And today's topic is a big trigger. So in last three weeks, we covered Apex programming. So I hope you have done all the exercises. So today I will be starting the new topic. And this topic we will be discussing this week and next week, right? So Apex trigger is very much important and it is an automation tool that is available in Salesforce. And whatever we have studied in Apex programming, everything we will be using while working with Apex trigger. Okay, so once again, welcome everybody, those who are joining live and those who are like who will be watching the recording. So I hope you will also learn a lot through this stream. And moving forward, if you joined this bootcamp today only and you want to know who am I. So this slide represents what I have done so far and what I am doing. So I am basically having 16 plus years of experience. I have both education and IT experience. So in IT, I just learned Salesforce and due to education experience, I am just training students, freshers and professionals so that they can learn Salesforce. So this is me and like I started this bootcamp in January and till now like 43 sessions are done. And this is number 44 and I think total 100 sessions will be there. So I am trying to explain each and everything in detail and I expect like you are following all these learning best practices. So today we are starting new topics. So I am just going to explain these in detail. So you need to do proper focus on live sessions because all the topics are connected. So in trigger, we have different scenarios that we need to understand. So if you follow all the sessions then only you will be able to understand it properly. So I will give you self-practice exercises as well. I will give some demonstration in the session. So you just need to take proper notes for future reference. You can write down doubts and you can ask them in Q&A part of the session. So those who are following these live sessions regularly, they know. Like first I complete explanation and demo and then I try to answer each and every question in each session at the end. So this makes this bootcamp and channel unique. So I bet like you won't see any channel who is doing live sessions regularly every week and answering each and every question in the live session itself. So there are many organizations. They are just stealing paid courses and then they do one live session once in a week or so. So I don't think that make any sense because learning needs consistency, right? So I'm just trying to build a platform where you can just learn things consistently and your all questions should be answered. So don't miss any session and practice each session. If you face any doubt during practice session, so like I have created a telegram self help group and that group is very active. People are helping each other in that group. And if you have not joined this group yet, so I just shared the link of that telegram group in the chat. So please do join because this week and next week you will utilize that group a lot because there will be lots of doubts. And through that telegram group, you can share your questions and who have solved the problem they will be answering, right? So after joining, you will realize like 24 hours that group is active, right? Someone is asking questions. Someone is answering. So this way people are learning and sharing their knowledge and keep doing above every day so that you can build strong foundation. So like consistency is the key. So if you are learning, then you should be consistent. If you are like sharing your knowledge, like I am sharing my knowledge. So I am consistent. So everywhere in the in our life consistency matters, right? So the way we live our life life like for survival on a daily basis, we need to eat food, right? For survival, we need to breathe on a daily basis. So these two processes are consistent, right? So learning and sharing should also be consistent. So don't think whether you will be getting any job or not, or if you are already in job, so what will be your future? So don't think much about that. Just focus on learning first. Once you have proper learning, then you can just think about that because if you do worry and learning simultaneously, then you won't be learning much, right? So I would suggest consistency is the key. So do watch all the sessions, do all the practice. Everything is available free of cost. You just need to pay your time, right? And I think everybody can spare two to three hours on daily basis, right? So I am also sparing three hours on daily basis for you so that I can prepare the content and deliver it, right? So if you are if I am doing this for you, so you can also do it for yourself. Okay. So first I will be explaining about trigger will give one demo and then I will take all your all your questions and we'll try to answer. Okay. So these are two places where you can ask questions. I think Telegram group is used frequently so you can go with that. But if you want to ask questions, you can like send your questions in the comment sections as well. So this is our bootcamp timeline. So as I promised, like I am consistent. So this is week 12, right? So you can see how consistent I am. And I am sure lots of folks are consistent in learning as well. Right. So I'm happy for you and I congratulate you. Like you have like you are about to complete 12 weeks this week. Right. It's almost almost three months. Right. So by the end of this week, this bootcamp will be completing three months. And I am sure like there is no other bootcamp running in entire Salesforce ecosystem for so long and totally free of cost with everything explained in detail. Right. So just follow this. Like Sanjay Gupta Tech School everywhere on YouTube, LinkedIn, Instagram, Telegram. See all the notifications. All the important links are available. And please share the channel with others as well so that they can also start their journey so that they can have some job. And like soon you will see a cybersecurity session will happen. So in session tracker, I already mentioned the date if I take you to the session tracker. So here you will see a cybersecurity bootcamp. I will be launching on 20th April and from tomorrow I will start sharing like details about that bootcamp. So we have decided like to do this bootcamp in different phases because we need to know the feedback from people like how they are feeling with that bootcamp. Right. So all the all the details I will be sharing in the next week so that you know what cybersecurity is. And if you are not having any job, you're fresher and you're struggling. So you can just start working as a freelancer. Right. Because that is also important. If job is there, then that is okay. If job is not there, you can just try and do some freelancing work. Okay. So I hope this will help you. Okay. Yeah. I know video got stuck. So I just like change the setting. Actually it is due to some internet issue. Okay. So this was brief about what I did, what I'm doing and what I will be doing. So this is the first session of trigger. So I took long to explain all that stuff. Now I'm just moving on to the topic. Right. Because if you are joining particular sessions, so understanding topic is very much important. So today's topic is epic trigger in Salesforce. So now I'm going to explain this for you. Okay. So first of all, we need to understand the introduction of trigger. Like what is trigger and why we use trigger. So here, lots of points are listed and these points you can explain in an interview as well. Like if in an interview interviewer ask you, like what is trigger, what is a big trigger, why we need a big trigger. So you can say like triggers are initiated when a record is inserted, updated, deleted and undeleted. Right. So if you do any of these four operations on particular record, so your trigger is basically initiated. Right. So this is the first point that you need to remember. Next point is use trigger to do operations that cannot be done by point and click tools provided by Salesforce. So, you know, like we have workflow rule process builder flows, but workflow rule and process builders are deprecated now. So we have flow and in flow we have different types of flows. So if you are unable to implement any complex solution with flows, so you can just go and implement that solution with the help of trigger. Right. Because in trigger everything you need to do with the help of custom code. Right. So in complex scenarios we can implement with trigger and we can do things using trigger that we can do through apex. So whatever you can write in apex everything you can use in trigger as well. So that's why it is basically known as apex trigger. So trigger means whenever you are creating, updating, deleting or undeleting any record. So some process should trigger trigger means initiate. Right. So whatever code you will be writing in the trigger that will be apex code only. Right. Including SOQL and DML or calling some methods. So SOQL, DML, method classes, those everything we have already done. So the base is already built. We just need to use that base so that we can understand how basically trigger works. So triggers can be created for both standard as well as custom objects. So we'll be doing it for both. So in demonstration I will be using standard object but in our exercise sheet I will put some scenarios around custom object as well. Okay. So that you can just prepare yourself well and we can perform custom operations before or after events. So this is very important. Second last point is very much important. Here we have two words before events and after events. So in trigger we have two types of events that we need to understand. So I will be explaining what before event is and what after event is. And by default triggers are active as you create them. Okay. So these are some point that you can explain while answering what is trigger in interview. Okay. Now moving forward. So we have two types of triggers. One is before and one is after. Okay. So if I go back so I already told you we have two types of events before and after. So you can say before trigger it is used to update or validate record values before saved to database. So for example if you are creating any record and before saving that record into database if you want to do some changes in that record with the help of code. So that process you will be executing with the help of before trigger. Okay. And second we have after trigger. So once your record is saved to the database and if we are talking about insert operation. So once your record is saved to the database so for that record ID will be generated. So for example if you have created any record for example if you have created any record and you want to use that record ID for any processing purpose. So in that case you should be using after trigger because newly created records ID will be available in after trigger only. Right. And if you want to do something on the related record. So I hope this you remember we saw in flow as well in flow. In flow we have fast field update and actions and related record. Right. So fast field update is equals to before trigger and actions and related record is basically similar to after trigger. Okay. So for example if you are creating account record and you want to do something with related contact or opportunity. So in that case also you will be using after trigger. Okay. And the record that fire the after trigger are read only. So in the trigger in the after trigger the record who like which initiated that trigger that record will be read only. So in that record you won't be able to do any modification if you want to do modification you want to apply a particular DML operation. Right. So this is brief difference and I hope right now if you are a beginner if you are a beginner and never wrote any trigger so it might be confusing. But when we will be implementing some examples so it will be very much clear for you like when to write before triggers and when to write after trigger. Okay. So if if you see this so every day like tomorrow day after tomorrow we will be doing a comparison based scenario implementation. So I will be implementing before insert versus after insert before update versus after update before delete versus after delete versus after delete. So this way we will be implementing scenarios in such a way so that you can understand when to use before insert and when to use after insert. Okay. Now this is very much important to understand. Okay. So just just go through whatever is written here in the table so that you can understand the difference between like what what it means like record is saved to the database and what it means like record is committed. So here five sections are available. First section says if you are doing insert update absurd or delete operation on a record. So just after that all before trigger executes then record is saved to the database but not committed yet. It means record is saved to the database but not committed. It means it is temporarily saved. If there is any error in the process. So whole process will be rolled back like so that's why that's why this third block is important. So record is saved to database but not committed yet. Then after saving into the database all after trigger executes and then your commit operation will be done with the help of dml operations like so these are like brief steps. So I just identified five steps but we have whole order of execution. So you can see here I have a link so I'm just opening it so that you can see it in detail. So if I show you this trigger and order of execution. So here you can see it is mentioning when you save a record with an insert update or absurd statement Salesforce performs a sequence of events in a certain order. Right. So here all the orders are mentioned. So first of all loads the original record from the database or initiates the record for an absurd statement. Then lots loads the new record field value from the request and overrides the old value. So this way all the steps now here step number three says execute record trigger flows for says execute all before trigger. So this way duplicate rules then here number seven says save the record to the database but doesn't commit yet. Right. So record is saved but it is not committed. Then execute all after trigger then assignment rule utter response rule work for rules. Everything is listed escalation rule then record triggered flows. Those are configured for run after the record is saved and entitlement rules. Then here you can see execute criteria based sharing and then step number 19 says commits all DML operations to the database. Okay. So now I hope you understand the difference between save to the database and commit to the database. Okay. So I hope this is clear to everyone. So I'm just sharing this link so that you can also go through with this. So just open this link which is available in the chat and you can go through with this trigger and order of execution so that you understand everything. So moving forward. So if I go back so just just see this again. So before save we execute before trigger after save. We execute after trigger and then commit operation is done. So everybody needs to remember all these steps while working with trigger. Now if I go forward so here you can see trigger syntax is available. So first of all you need to write a trigger keyword then name of the trigger then on object name and then trigger events. Okay. So this is a syntax and I will be explaining one example today so that you understand how we can write it through developer console. Okay. So moving forward. So here we have trigger events. So we have total seven events before insert before update before delete. So in before case we have three and in after we have four after insert after update after delete and after and delete. Right. So these are total seven events available that we will be using while implementing the trigger. Okay. And with name like insert update delete it is clear like when this event will be working and before and after you can just understand with this. So before means if you want to do something before record is saving to the database and once record is saved to the database then after that if you want to do something then we go for after. Right. And then once all the operations are done then your record is committed to the database and once record is committed to the database it means it is permanently saved. Okay. So these are total seven events that will be discussing. So today I will be explaining before insert but not much in detail because tomorrow we will be discussing before insert and before sorry before insert and after insert in detail. Right. So moving forward so this is our example number one which will tell you how you can write a trigger and while implementing trigger I will tell you some best practices as well like how you can implement your trigger what best practices you need to follow by implementing the trigger. Right. So like while implementing I will be explaining them but separately I will be having one more session where I will be explaining you the best practices of Apex as well as trigger. So both topics are related that's why I will be keeping that those things in one session only. So here you can see this example says trigger is the keyword the name of the trigger is account trigger. So this is part of best practice. Don't write any name for the trigger it should be object and then it should be appended with the word trigger. So if you're writing trigger on account object search should be account trigger if you're writing trigger on contact object it should be contact trigger if you're writing trigger on case object it should be case trigger if you're writing trigger on position object that is our custom object we implemented in the project. So your trigger name should be position trigger. Right. So first you need to write the object name and then it should be appended by the trigger world. Right. Then here we just have the system dot debug so that we can see whether trigger is working or not. And I already told you when trigger will be initiating whenever you will be creating updating deleting or undeleting any record. So right now I'm using just one event that is before insert. So whenever I will be creating any record so this trigger will be executing. Okay. So I'm going to implement this example in the org. So here you can see developer or developer console is already available if I click on file and new. So here this apex trigger option is available. Right. So you just need to click on apex trigger then this window will appear and here you just need to write the name of your trigger. So I'm writing account trigger because I'm going to create a trigger on account and if you click on this drop down so all your standard and custom object will be listed here. So you can just crawl and search particular object. You can select it and you can just click on submit. So this way your trigger is created and here you can see the extension. It is a P X T if you create any class so it is a P X C but if you're creating a trigger so it is a P X T right. So this way I have created a trigger so trigger is the keyword this trigger is the keyword then this account trigger is the name of the trigger then on account this account is the object right. So this object name will come automatically because at the time of trigger creation we selected it. Okay. And this is the default event before insert event will come automatically. Right. So right now I'm not focusing much on these events because this we will be comparing tomorrow. So as of now you will be using before insert because at least one event is required and if event is not available then your trigger won't work. So this trigger will work on insert operation before says like if you're you're creating a new record. So before the record is getting saved to the database so prior to that if you want to do some task then you can do it in before insert right. So here I'm just writing system dot debug demo trigger with before insert event. So this way I'm just writing this system dot debug statement in the trigger and I'm saving it right. So in last three weeks in last three weeks when we were discussing about apex programming so you saw every time I was implementing a method inside the class and I was opening this anonymous window and I was calling methods like this. I was doing this whole three weeks and you were saying like every time we need to call the methods like this. So I was saying no these methods we are calling here for testing purpose when we'll be working with trigger. So these methods will be executing automatically. So now if you want to run your trigger code whatever code we have written here if you want to run this code you don't need to open your anonymous window. You don't need to open your anonymous window to call particular method what you need to do you need to create a record. So this trigger we wrote on account object right this trigger we wrote on account object. So I'm moving here and going to create an account record right so I'm creating account record active required so I'm populating it and clicking on save. So this way account record is created. Now if I go here and click on logs so here a few log documents or log files are available. So I need to open them one by one. So here we don't see any debug if I open the second one. So here also I don't see any debug statement if I open the third one. So here lots of statements are available and if I click on debug only so here you will see this line number two is showing demo trigger with before insert event. So it means the code which I implemented here is working on creation of account record automatically. So this is basically trigger. So whatever code is written inside the trigger that will execute whenever your record is created or updated or deleted or undeleted as per the events that you have implemented. Right. So this is one demo that I gave you so I just created the record from UI. Now if you want to test this trigger execution by creating a record through code that is also possible. So what you can do here you can just try to create new account record. So this way you can just try to create a new account record. Okay. So if you insert any account record then open log is checked already. So logs will be opened and in that log you will see the debug statement. Right. So I'm just executing this. Okay. Active is true. So we just need to populate that as well. So active field we need to populate as yes because it is required field. So again I'm clicking on execute now it is executed locks are opening and I'm just clicking on debug only so you can see the result. Okay. So this way if you implement a trigger so that implemented trigger you can test through two different ways. One you can create your record from UI and another you can create your record through code in both the cases your trigger will work and you will see the results in the log why in the log because right now the code which we have implemented is having system dot debug on right. So this way I just gave you brief demo like how you can create trigger and after implementation of trigger how you can just test it. Okay. If you are a beginner then I hope this information is very helpful for you. Now I'm just moving forward. So after understanding how we can implement trigger and how we can write events how we can write code how we can test it. So in trigger we use some context variables as well. Okay. So all triggers define implicit variables that allow developers to access runtime context. These variables are contained in the system dot trigger class. So basically we have a class that is system dot trigger. So we'll be using this and here you can see we have lots of context variables. So is executing is insert is update. So this way like is executing means whether your code is initiated through trigger or something else. So that we can test using is executing right next is is insert. So is insert will check whether your initiating like trigger initiating operation is insert operation or not then same for update then we have delete then we have is before is after is undelete and size. So all these are context variables that we will be using in the code right. So if I want to give you a brief example of this like how we can write it. So here what I can do I can write if trigger dot is insert then if trigger dot is before now inside this I will be writing the code like this. So this way this is insert and is before is context variable right and here you can see this trigger is the class and here this is insert and is before these are context variable which are already defined right. So we need to know the context like this code will be running in before insert or after insert what. So this way in that particular context your code will be executing if I go further. So here you can see we have lots of context variables. So time to time we will be using so we'll be using after before delete undelete update insert is executing all we will be using. We can also check the size of the like trigger invocation like how many records you have inserted or updated or deleted or undeleted right. So what is the size of record number of record. So that also we can check then we have few more context variables which are new new map. So basically whenever you create any record so that newly created record information will be available into this new list. This new is a list of S object type. So whenever you will be inserting updating and undeleting like particular record so those will go to new and new map is basically map of this list. So this new is list and new map is mapped both will be having same data but new is list and new map is mapped. Okay. So just read all the statements which are written over here and then I will show you a table as well so that you can just compare everything. So new and new map is for new records but if you are updating any record if you are updating any record so the old values like record will be having two different inter in instances. So if I take an example so for example here I am going to update this record. I am going to update this record. So right now this record is having account name as ACC 1303. Okay. If I modify it and if I write this ACC one double zero so this is new value. So this is one record this account is one record but it is having two different values for account name field. Older value was ACC 1303 and newer value is ACC one triple zero. Okay. So record is same but is it is having two different values for one field or if you modify some more field let's say rating is hot. So earlier rating was none. Now it is hot. So I modified two fields. So record is one but it is having two different values old value and new value. Right. So I hope this way you are able to relate record is same but it is having two different values. One is old value and one is new value. So what will happen? Old values will go to this old list and new value will go to this new list automatically in case of update. Right. So record is same record is same that you are updating but that record will be having two different values. One is old value and one is new value. So old values all the old values whether you are updating record or not old values will go to the old list and new values and those fields which you have not updated all those will go to the new. So this way this old list map or new list map we basically use. So you can just understand it properly with the help of this table. So just go through with this table. So here all the trigger events are listed. Total seven events are available here and on top you can see we have four context variables. So whatever operations you are performing basis on that your result will be available. Okay. And I just removed the video. I just removed the video so that you can see the table completely. So once you go through I'm giving you couple of minutes so that you can explore this table. Once you explore it completely then I will turn on video so that nothing miss. You don't miss anything. So here in this table you can see if we are performing insert operation. So in case of insert we will be having values and trigger dot new list in new map in before insert we don't have anything in after insert we will be having the data because map contains ID and in case of before insert ID won't be available and in insert we won't be having any old values for that particular record. So these are null. In case of update all new and old will be having values in case of delete new will be having nothing it will be null because we are deleting so we always delete old records. So trigger dot old and trigger dot old map will be having values new won't be and same with undelete undelete will be having new values because undelete means we are restoring values from recycle bin. So those are considered as new records and it won't be having any old values. Right. So this this table is very much important as per interviews in interviews basically interviewer ask the differences between all these four context variables. So with the help of this table you will be able to explain the difference between all the context variable with regards to different events to the interviewer. Right. So I hope you are able to understand it. If you want you can just take a screenshot otherwise you can anytime go through the recording and you can just see the comparison. Okay. Or maybe I will be sharing this image in the telegram group so that it will be available with you always. So moving forward now I'm going to explain the example again. So someone is asking like can I implement this example with the help of trigger handler so I will be doing that. Yeah. I will be doing that and one more question is there whenever we will be undeleting the record. So I think I ID I'm not sure ID will be same. So we just need to figure it out. So when we'll be doing undelete so we will confirm that. Right. In my opinion it should be same but we'll check. Okay. So this is example two. So first I will be writing the logic in the trigger itself. And then I will show you how we can separate it. So I will show you trigger handler as well. Okay. Trigger and trigger handler. So just have some patience and be with me. So we'll be doing everything. Right. And remember today I'm not focusing much on the events I'm just focusing on how to write the trigger and how to test it and how to write the trigger code using trigger handler. So this example number two. First I will be implementing it in the trigger itself and then I will be implementing trigger handler class. Okay. So first we need to understand the requirement like what we are doing here. So we are just assigning test description in the description field. So what will happen whenever record is created whenever any account record is created. So in that case this test description will be assigned into description field automatically. Right. So moving forward, moving to developer console. So here I'm just removing the statement. So now I'm going to use these context variables as well. And here I'm implementing for loop and here I'm writing description. So this way I just implemented the trigger. Okay. So if you see here, so I just implemented this loop and whenever you are learning trigger, so you will realize everything is apex. Just few lines are different. Rest of the code is similar to apex. So that's why these are known as apex and here you can see this is important. Trigger dot new. This is important. Trigger dot new. So we already discussed about this. If I go back, so here you can see we have trigger dot new in case of before insert. So whenever you insert any data, so all the newly created record will go to this trigger dot new. Okay. So this trigger dot new is basically a list. Trigger dot new is basically a list. Trigger dot new is an S object list. Right. And this trigger dot new can contain lots of records and one by one those records will be available in this ACC and through this statement ACC dot description. We are just trying to assign account is created into this field. Right. So this way we are implementing this code in trigger itself. So I am just saving this code and I will be testing it through three different ways. So first I will be creating a record through UI, then I will be creating a record through code and then I will be creating bulk records through code. So whenever you write trigger, you can apply all three mechanism. Okay. So trigger is saved. Now moving here, canceling this record. So here you can see description is blank. This is the previous record which we created. It is not having anything in the description. So it means before implementing this code description was blank. Now we have implemented this code so that description will be having this text account is created. So coming here creating new account record filling all the required fields and here you can see description is blank. Now I am just saving it. Moving to details. If I scroll down and go to description, so here you can see account is created is populated in the description. Right? So this way you can see how trigger is working in the background automatically whenever I created the record. So this I showed you how we can create record through UI and test our trigger. Now we will be doing same through code. So through code first I will be creating one record. So here you can see this data is already available. So I'm just modifying it. Okay. So account name will be one two three zero four ACC one two three zero four. So this account will be created and this time we don't need to open the log because if you see the code. So here system dot debug statement is not available. This time we are going to update particular field. This time we are going to update particular field. So if I run this code. If I run this code. So what will happen or record will be created and trigger will initiate automatically. So I'm just clicking on execute record is created. If I go here click on account staff. So here it is one two three zero four. If I open it go to details. So here you can see. Account is created. So if I try to create a record through code then also our trigger is working fine. Right. Now I'm going to show you how you can create bulk record. So I hope you remember we did it in apex as well. So if you want to create bulk records you just need to create a list. So here I'm creating a list of account. Now I'm implementing a for loop inside this for loop. I will be creating account records and here I am inserting five records together. So here account name is ACC then triple zero and then I concatenated I here. Right. Then added newly created account into. This account list. So here just instance will be created once this loop is completely executed. Then this insert ACC list will execute it will be inserting five records and all those five records description will be having record is created. Okay, that's why you can see here we have implemented this loop. So the five records that we are creating through code. All those five records will be available here. So that's why it is suggested whenever you are implementing any trigger. So trigger should be bulkified. So if you write trigger dot new here in this loop. So this trigger is bulkified trigger. It can handle one record as well as it can handle more than one records as well. Right. So now sorry. I mistakenly closed developer console. I'm just opening it my bad. Okay, so here you can see this file is open. Now I'm going to open anonymous window. So I just need to write that code again. So this is the drawback of anonymous window window. Whatever you write if you mistakenly close your console. So everything will go on. So I'm just implementing it again by mistake. I just closed developer console. So here it should be in teaser i equals to one. I less than equals to five i plus plus and then account ACC equals to new account and this time I'm writing it in new line. You can write in that parenthesis as well but due to less space I'm writing it in new line. Okay, so this way total five records should be created and the trigger will be executing. So I'm just clicking on execute. So code executed. Now if I come here so you will see five records here you can see ACC 001 2345 five records are created. I'm opening them one by one. So I just open this ACC triple 01 if I go to details here you can see description is account is created. So if I go back and open this one 0002 go to details. So what is happening here? Description is account is created. So this way all the records that you created if you open them so all those records will be having description as account is created. So this way I hope you understood how we can implement a trigger having actual logic. Which is actually updating particular field before record is saved to the database. Okay, and we tested it through three different ways. Now moving forward I need to show how we can write trigger and trigger handler separately. Okay, so this is the code that I will be implementing and here above part is trigger and below part is apex class. Okay, so here I'm going to create new apex class and I'm naming it as account trigger handler. So this is also best practice if you are writing any handler class or apex class for any trigger. So its naming convention should be account trigger handler. So whatever name you have used for trigger so it is account trigger. So you just need to use account trigger handler for your apex class. And here we can implement a method public static void then I'm naming it as update description it will be receiving list of account acclist, right? I'm just saving this code. So now everybody remember we are implementing static method here. So I told you in last three weeks if we implement any static method. So we can call that method directly without creating any instance we can call that method through class name so that we will be doing in the trigger now. So in trigger this logic won't reside. I am just cutting it and pasting it here and in trigger what will happen we will be writing account trigger handler name of the class and then name of the method and here I will be passing trigger dot new as a parameter. So this account trigger handler is the name of the class update description is the name of the method and trigger dot new I am passing as a parameter right. So this trigger dot new will be receiving all the newly created record in the trigger and through trigger we are passing all the data into this method this method is available in this class right now if I move here so here you can see I have already created acclist in the first line so trigger dot new that we are passing through trigger that data will be stored in this acclist now here in place of trigger dot new I will be writing acclist removing this comment so this is the trigger handler class method so this method we are implementing and here you can see the code is available with the help of loop so this way you can separate out your trigger and trigger handler right so this is our trigger and this is our trigger handler and now for testing purpose you can apply the same steps so the steps which we applied in the previous example same steps you can apply so we saw three steps like creating record through UI we saw like creating record through code and bulk record so on this example you can apply same right now what I can do if I try to create new record from here so same operation will perform so I am creating account record going to details and here you can see account is created is populated right so this way this is appropriate program so the last example which I demoed you this way we implement the trigger and this way we implement the trigger handler now we need to understand like why we separate them out so the reason is if you implement all the business logic in the trigger so trigger will be so complicated to handle so what we do instead of writing all the code in the trigger we shift the business logic in the trigger handler class and here we can have different different methods and the methods which we define here those methods we can call here directly okay so we will be having lots of methods called in the trigger and anytime if you want to change that calling order or if you want to comment particular method so that you can control with the help of trigger only so in trigger we don't write any business logic in trigger we just call the methods and business logic or process we write in the handler class and they that handler class can have any number of methods so I hope this answers lots of questions okay so so this is you need to remember whenever you write any trigger scenario so you will be testing it through UI you will be testing it through code you will be creating bulk record through code and you can test it out and later we will be having one more like way to test the trigger code that is Apex test class right so that we will be implementing once trigger topic is completed so at that time I will explain you so this is very easy and always remember whenever you implement any trigger you need to test it for one record as well as for bulk records so yes Phyrus is asking do we need to create one handler per trigger yes so the idea is if you have one object so for that one object there should be one trigger and for one trigger there can be one trigger handler or more than one as well because in trigger handler you will be defining the methods so if they are more than one then also it is fine okay so lots of people are life learning and that is great so now jumping on to the Q&A so I am going to take questions from the beginning so I think there are less questions today so if you like after this complete explanation now if you have any question so you can ask because I don't see any question relevant everything I already explained if you want to ask any new question you can type it in the chat so that I can explain and I can see people are helping each other as well so that is good yes really so we will be using map so don't worry I will try my best to demo you all three things list, set and map so guys if you have any question you can go ahead and you can ask so I just explained the introduction today and tomorrow we will be doing all the scenarios no theory only demo so tomorrow we will be doing before insert and after insert okay so now if you have any question so you can share with me and if you don't have any question you have understood and you want to enjoy IPL or whatever you want to do you can okay Amar is asking if interviewer asked explain the trigger how we will answer that so I think this I already answered Amar so I explained you introduction to trigger so just go to the recording in the beginning I explained introduction slide so that you will be explaining okay Pranay is asking can you please explain handler once so Pranay handler is very easy handler is basically an apex class and here I implemented this one method here business logic is available this method will be receiving a list and this list is basically trigger.new where all the newly created records will be stored so you need to pass it and here we will be receiving and then processing so loop I think you already know if you so one more thing if you are directly understanding trigger so you won't be before understanding trigger you need to go through all previous three weeks sessions those are related to apex because I am always repeating in sales force everything is connected so you should be consistent enough if you want to understand the topics right so Manoj I already explained like best approach implement trigger and shift your business logic in the trigger handler this recursive trigger we will be discussing so if you guys please please go through with this session tracker so in this session tracker everything is available so recursive trigger we will see next week Monday right and the link of this session tracker is available in the description of this video so just go through session tracker if you want to understand things thank you Joe's manual for appreciating my session yes Govardhan I will be explaining about roll up somebody through trigger so soon as we are not fetching records through trigger we are just creating the record and those will go to trigger automatically so go be Christian trigger basically we implement through code and trigger is a declarative point and a click tool and flow has some limitation those we don't have in trigger Raghava I already explained trigger two three times so just go through and watch the recording now so Nagarjuna the trigger scenario you posted if someone is knowing that so they will be helping you surely so Shilpa is asking how much time it will take to become a pro in epics consider we are new to epics so it will take around five to six months if you do regular practice because it is coding and coding you can just understand through practice only so if you do consistently practice for six months include apex trigger test classes you can include as in grown as epics integration so everything if you practice for six months at least then you will become expert okay so next is so when you for your question data is basically stored in the cache cache memory the variables which we are creating so you can you can say cache or ram will be storing it is not stored permanently so it is available in the list and once you insert then it goes to the database so upper night already answered this question we are creating handler so that we can separate our business logic through trigger so tomorrow when I will be explaining more scenarios so our trigger will be calling more than one methods then you will be understanding the real advantage of implementing trigger so Srivalli you asked very good question and the answer to your question is all the records will be rolled back if anyone is failing whole process will be rolled back thank you Rahul thank you Sikander thank you Gobi Grish thank you Anuj for appreciating my efforts so I think all the doubts are clear and everybody is good so if you still have any question please ask so that I can just end the session so Srivalli can you please are you asking this questions like in relation to the previous part Rekha yes it is possible we can write trigger on two unrelated objects but there will be two triggers one trigger will work on one object only one trigger cannot work for two objects thank you Sopan thank you Nusrat yes Nalla Vamshi we can use database dot insert in triggers so at the time of DML operation we can use it thank you Chandan Faizan Rekharsan we will be learning later so Shivam Pandey trigger event executes once so Sanjit save data means data is stored temporarily and if you are inserting the data so ID will be created and commit means like it is permanently saved in the database so when your record is saved to the database but not committed so after that if something is breaking your whole process will be rolled back but commit means your data is permanently saved so after that your record won't be rolled back this is basic difference thank you Revvi okay Srivali got it so Srivali basically if you use database dot insert like database class methods then only you can control success and failure other than that if you use DML operation so it is like all or none so Scyther ID if you want to deactivate trigger you need to go here and you can search apix triggers and from here you can deactivate so you just need to edit it so here you can find this checkbox is active so if you uncheck so your trigger will be deactivated so from here also you can just change the code so everybody you can search apix classes and apix trigger from here in the setup and you can control them from UI also so Chandan if you want to know record is committed you can just see the logs if everything works fine then your record is committed if it is breaking then it is not committed okay so I think I answered all the questions and I don't see any new questions so thank you everybody for joining this session and tomorrow we will be discussing lots of scenarios related to before insert and after insert and soon you will hear about the upcoming cyber security bootcamp so if you are not interested and you just want to focus on sales force you can do and if anybody in your relation like your employees senior junior any anyone in your circle want to try their hands on cyber security so just share information with them ask them to join or to subscribe telegram group so that you can get all the information and just for your knowledge sales force and cyber security both will run in parallel right so maybe I will little bit adjust the timing so I will let you know but this week and next week there will be no change and both will be happening on different times so this will be as is no change I will be delivering all the sessions and cyber security session me and my friend we both will be there and it will be on separate time so it is on you whether to attend or not right so if you want to go in that direction you can if not then you can just share the information with other people and it will be for six weeks so that proper knowledge will be shared and I hope so this will be one more step ahead from this channel for the community so that I can break the change like education is not a business okay thank you Srivalli for this appreciation and yeah I think that table basically contains everything so that's why you got all the information together okay so guys fresher and freelancer job for cyber security we will be discussing and for salesforce you just need to play around with LinkedIn so just explore LinkedIn and try to research some freelance website and try to search but for fresher freelance salesforce work is very less so just follow the LinkedIn okay guys thank you so much for joining today's session and tomorrow we will be learning more stuff thank you bye everyone see you tomorrow