 Hello, hi, everyone. I'm Sanjay Gupta. I welcome you on Sanjay Gupta Tech School. So here you can see today we are having day 45 and we'll be discussing about how we can implement before insert and after insert event with the help of Apex Trigger. So yesterday I gave you a brief introduction about Apex Trigger, like how we can implement Trigger and how actually trigger concepts are available. So I hope you have gone through with that video. So those who joined live, they understood and asked various questions and those who watched the recording. So I hope you are pretty much clear with Apex Trigger concepts. So now today we'll be implementing a few use cases so that you can understand when to use before insert and when to use after insert. Okay. So hello and welcome everybody once again. And I am going to start today's session. It is day number 45. So those who have started bootcamp from this week only. So if you need to know about me so you can go through with this slide which shows whatever I have done and whatever I am doing, then I hope everybody who are following this bootcamp, they are following all these learning best practices. So basically, you don't need to miss any session because all the sessions are connected. So if you are a beginner, so in that case, if you want to understand every topic, so you just need to go through with all the sessions so that you can understand them clearly and be consistent because consistency is the key and do regular practice. If you need a practice question, so here we have a document where all the practice related questions are available. So yesterday I explained you the concept. So you just need to go through the recording. And for today's session, whatever I will be demoing are available here. And I provided some scenarios for your self practice. And all these scenarios are having these reference videos. So whenever you get stuck, you can just go and watch this recording as well. Okay. So be consistent and do regular practice. And if you need a link of this exercise doc, so it is available in the description of this video. Okay. So today I will be explaining the examples and maybe I will pick the questions in between because I will be explaining the scenarios only today we won't be discussing any theoretical part. So if I see any important questions, I will take it in the middle. And still if you want to have a conversation, so you can join this telegram group. And lots of folks are discussing doubts there. So you can also become part of this. And we are in week 12. So in week 12, lots of scenarios related to apex trigger I will be completing. And next week, this trigger topic will be completed. Okay. So just follow me on these social media platforms and all the important links are available in the video description. Right. So now moving forward. So as I told you, like today, I announced the date as well. So from 20, 20 April, cybersecurity boot camp will be starting and it is somewhere related to Salesforce as well. In Salesforce, we have a job role which relates to cybersecurity. So on 20 April, we'll be doing all the we'll be briefing you about the program. And if you're interested, you can join. If you're not interested, and any of your friend, colleague, or junior senior, if they are interested, ask them to follow this platform so that they can be benefited. Okay. So today we'll be discussing about before insert and after insert and apex trigger. So moving forward, so two use cases I will be explaining for standard object and two use cases I will be explaining for custom object. Okay. So first of all, I'm going to explain before insert. Right. So before insert and for standard object. So we need to understand the requirement first. So requirement says if account industry is not null. So account is an object. And on account object, we have a field known as industry. If it is not null and having value as media, then we need to populate rating as hot. So rating is another field. So at the time of record creation, if industry is not null and its value is equals to media, then what we need to do, we need to just populate rating as hot. So this is our requirement. And here at the time of record creation, we need to perform this. So we are not working with any related record. We need to work on account record only. So if you are not working with the related record, it means you can perform this with the help of before insert. Okay. Now, if you take a look on below example, which says create related opportunity when account is created. Okay. So when you are creating an account record and on creation of account record, if you want to create a related opportunity, it means here on account creation, we will be working with a related opportunity means on related record. So in this case, you will go with after insert. So this way, you need to smartly decide whether to use after insert or whether to use before insert. Okay. So now, first of all, I'm going to implement the first use case, which is for before insert. So jumping here and moving to developer console. So here, you can see yesterday, we implemented this trigger. And in this parenthesis, I used before insert because it was available by default. Then I applied trigger dot is insert. It is a context variable than is before, then I just called update description. Right. Now I have one more requirement. So yesterday, I told you on one object, you have to implement one trigger only. And you can implement a trigger handler where you will be defining the method. So today, we have one more requirement. So for example, if you are working on a real time project, and in that real time project, if a trigger and trigger handler is already implemented, and you need you have a you have one more requirement that you need to implement. So what you need to do, you can just write one more method in existing trigger handler, and that method you can call on your trigger. Right. So here, I'm going to create one more method public static void. And as per the requirement, what we need to do we need to populate rating. So I'm just naming method as populate rating. Okay, now this method will be receiving an account list. So that's why I'm using it here. Okay, so this way, outline of the method I created method name is populate rating. And it will be receiving a parameter into this ACC list variable. Now, one more thing that you need to see, we have two methods. This is first method and this is second method. And in both the methods, we are using same variable name for this list. So that is okay. You don't need to create new variables name variable names for each method because the scope of this variable is local to this method. So if you have created a variable in particular method, so you can reuse that name into another method, that is perfectly fine. Right. Now here, I need to call it. So what I can do, I'm just writing it. And from here, I'm copying this method, pasting it. And from here, I need to pass trigger dot new. So this way, in the same block, in the is before block, I called two methods, right? So if you want to run two methods for before insert, so this way you can call them. And in both the methods, you need to pass trigger dot new. So whenever your new record will be created, so first this method will work. And then this matter method will work. So as per the order, you are calling the methods accordingly, they will be executing. And anytime, like if you don't want to run particular method, so you can just comment it. If you comment, so that method will be available in this handler class. But in trigger, it is commented. So it won't execute. So this is the benefit of implementing trigger and trigger handler separately, right? So I hope this brief explanation is fruitful for you. Now I'm uncommenting it, saving this trigger. Now I'm going to implement this. And I can see there are a few questions. So let me implement this trigger first, trigger handler method. Then I will test it. And then I will pick the questions, right? So after each scenario, I will be picking a few questions and then we'll move on to the next scenario. Okay. So here, what I need to do, I can just copy this. So you can reuse the code which is already implemented because we just need to modify a few lines. So we need to iterate on this ACC list. So this loop will be same. Now we need to apply if condition. So if ACC.Industry not equals to null and ACC.Industry equals to media. So if both are fulfilled, so I knowingly put this null check because if it is not null, then only we need to check it. If it is null, then we don't want to do anything, right? Because sometimes if you check it with the value directly, and if your field is null, so null pointer exception can be thrown through the developer console, right? So if your code says like you just need to check particular value, whether it is available or not. So you can just apply null check as well for safe side. And if both the conditions are true, then in rating, you can just populate hot. And you don't need to apply any DML operation. This change will apply automatically. Because before events works before the record is saved to the database. This I already explained you just yesterday, like before saving the record into the database, your changes happens whatever you are doing in before events. So first before event or before insert will work and then you're saved to the database. Okay, so I hope you understood the concept. So this way I just implemented it and now I'm just saving the code. So you can see account trigger handler is implemented and account trigger is implemented, right? So now I'm moving forward and I just need to execute the code. So what I need to do, I yesterday I told you like we have different ways to test our code, right? So if you want to test our code, so we have three different ways. First is you can just test it from the UI, right? So if you go to the UI, so you will be able to create a record and then the created record you will be able to test whether it is like your trigger code is working fine or not. So I'm moving here on accounts tab and I'm going to implement or I'm going to create a record and just clicking on new and here I'm going to create a record. So naming it as ACC3401 and here industry I'm populating as media and active is required field so I'm populating it as yes, description is blank, rating is blank. So you will see both the trigger will work, right? Description will be populated and rating will be populated as per the triggers. So update description will update the description and this populate rating will populate the rating, right? So I'm just clicking on save. So here you can see account record is created and rating is hot. So you can see value of rating is hot because industry we populated as media and if I go down so you can see description is also populated as account is created. So our both methods which we called in the trigger are working fine, right? So this way I hope you understood whatever I explained here. Now I'm going to take some questions. So here, okay, so someone is asking about the timing. So there will be little bit changes in this bootcamp. So soon by the end of this week, I will update you about the timing of both will run on different timings. So I need to present in both. So that's why they will be available on different times. So I will update you. Yeah, fresher can learn cyber security. So we are planning our bootcamp in such a way so that fresher can learn cyber security properly. So Pooja is asking in one object how we can create multiple trigger per object we can create only one. So this is as per best practice. But if you want to create more than one trigger, so that is possible. But best practice says you can create only one trigger. The next is can we write trigger dot is before first and then trigger dot is insert later. Yeah, this is possible. So green up LWC is part of this bootcamp only in this bootcamp. You can see if you see the Excel sheet. So here I will be covering aura and LWC. So this is one bootcamp and cyber security is the other one. Don't think there will be separate bootcamp for LWC. LWC is part of this Salesforce bootcamp only. Then order of method is compulsory while creating trigger. Yes. So Shubham, in the order you are calling the method so that that matters, right. So calling matters. So here in the trigger, whatever order you are using that matters here, you can define in any order that doesn't matter. Right. So in handler, you can define in any order, but in trigger, whatever order you take, accordingly, your methods will be executed. So Prashant ready, we will be sharing all the details. So soon this Excel sheet will be having one more tab where everything related to new bootcamp will be available. Okay, very good is asking what is the difference between test class and test cases. So test class basically developer implement so that whatever apex code we have implemented, we can test it and test cases are created by the QAs. So QA basically create a few test cases, negative, positive, different, different scenarios. They test the functionality. So to test the functionality, if you are testing it from the UI, so for that, you will be creating test cases. But if you are testing your code through code, so for apex code, you need to implement apex test classes, right. So I'm asking, do we need coding language for cybersecurity? So I think no. So Avinash, we cannot do DML in before insert, right, because your record is still not saved in the database. So DML doesn't make any sense. So Nella, you are asking ACC.industry.contains. So it is incorrect because industry is a field. So on field, we cannot apply contains. So contains basically we can apply on collection variable. So this is not a collection variable. This is a field. So we cannot apply. So Praveen is asking difference between is empty versus not equals to. So is empty? Basically, we use with the collections. Here, what we are doing, we are comparing particular field. So if you want to compare particular field, then this not equals to operator can be used. You cannot use is empty because is empty you use with the list. And here ACC is just a variable. It is not a list. Right. So I hope this way you understood how I implemented this first scenario. So it was on standard object. Now I'm going to implement after insert. And for practice purpose, I already told you here, I already provided some use cases. So you just need to decide whether to implement it with before insert or after insert. So total six use cases I provided here. So after the session, whenever you get time, you can practice these scenarios for better understanding. Okay, so now I'm going to implement this second scenario, which I will be implementing with the help of after insert. So here it says create related opportunity when account is created. Okay, so whenever account record is created, we need to create a related opportunity automatically. So first of all, I'm going to implement a method. So I'm implementing it in the beginning so that you can view it on screen properly. So create opportunity. And here I need to write list of account. Right, so list of account and here also I'm using ACC list. Right. Now here I'm just saving this so that I can first call it in the trigger. Okay, later I will be implementing its definition. So I'm moving here. So this part is for before insert. Now here I'm writing else if trigger dot is after an inside curly basis, I will be calling that method. And I'm going to pass trigger dot new. So this way, this is your proper block. So whenever you need to work for before insert and before after, sorry, before insert and after insert. So this is before insert block. Here you can call any number of methods. And this is your after insert block here you can call any number of method. So this block you need to create once and you can just call particular methods whatever you are defining. Okay, if you want to use update operation update or delete so you can just create separate if else block for that. So tomorrow I will be explaining update operation. So I will let you know how we can add update operation in the same trigger. And one more thing we added trigger dot is after it means we want after insert to work. So what you can do here, you need to write after insert as well. This is important. If you don't write after insert here, so your method won't be working. So this is very much important, right? So in the first line, you need to write before insert as well as after insert, then only all the methods will be working fine. So now I'm saving the trigger. So trigger is getting saved. And now I'm moving to trigger handler. And in trigger handler, I'm going to create the method. So first of all, I'm creating list of opportunity. So this list of opportunity I'm creating because whenever I will be creating account records, so there may be chances I create five 1015 or maybe more bulk records. So if I create five records, so each account record should have one opportunity related. So that's why I just need to implement this method in bulky five form, right? So account list will be having lots of records. And those records will be we will be iterating. And accordingly, lots of opportunity records will be created. And those opportunity records will be adding into the list. And then through one DML, we will be performing the insert operation. So here I'm going to implement a loop and it will be based on ACC list, right? Now here, sorry, I am going to create opportunity instance. Now I just need to set all the required fields. So can can you guys tell me on opportunity what fields are required? Can you please tell me in the chat what fields are required while creating opportunity? So I'm just waiting for your response. So just put your response in the chat. Meanwhile, what I'm going to do I'm going to take few questions. So Jenna is asking recursive trigger. So yeah, I will be covering that. And if you practice all the scenarios that I I'm demoing and I'm giving you for practice, so you will become export. Yes, rather Krishna cyber security is completely different. And if you learn cybersecurity, so in Salesforce ecosystem, you can get a job as cybersecurity export. So other than admin or developer, you can get a job as cybersecurity export. Very good is asking I have an account object once I create an account object, we need to find how many related opportunities are there. We need to distribute the count. So very good. This we cannot do on account creation because on account creation, there will be no opportunity. So if you update any account or something like that, then only you will be able to count. So I can see lots of answers. So those who mentioned opportunity name, close date and stays, those answers are correct. So three fields are required, opportunity name, opportunity stage, and opportunity close date, right? So at the time of this instance creation, we need to populate them. So for opportunity name, I'm populating account name. So while creating account, whatever name you will be providing to the account with same name, one opportunity will be created, right? So we have only three required fields, those are name, then second one is close date. So for close date, I'm using a function that is today. And today function is available in system class. So this way you can write, so it will store today's date into close date. And then you can write stage. So if we go to opportunity, so here we have a pick list. So if I open opportunity, any existing opportunity if I open, and if I go to details, so here you will find opportunity, stage, pick list, and these are the values. So I'm just picking prospecting, whatever opportunity will be created, its stage will be prospecting. So here in single quotes, I'm writing prospecting. Okay, so this way all three required fields I have populated. Now, one more question to you. So if I want to connect this newly created opportunity with the account, so can you tell me what statement should I write now? So that this newly created opportunity can be linked with the account. Just write your answer in the chat. The question is, what statement should I write so that this newly created opportunity will be linked with the account? So you just need to write the complete statement, so that after your response, I will be writing that. Meanwhile, I'm checking if there is any question. So Praveen is asking which is best way. So in your case, you are writing trigger dot is before and trigger dot is insert. So in that case, if you write trigger dot is after and trigger dot is insert. So is insert you're repeating twice. So in my case, I am writing that once in your case Praveen, you will be writing it twice. So I think my way is better than yours. But yours will also work. So you can apply that as well. Okay, so I'm just checking the answer. So Vishal's answer is correct. Others is incorrect, or maybe incomplete. So Vishal mentioned correct answer. So we need to write OPP dot account ID equals to ACC dot ID. So on opportunity, we have a field. So maybe few folks mentioned the field API only. In that case, it is correct. So if you write OPP dot account ID, so account ID is a lookup to account on opportunity. So we just need to copy account ID into this lookup field so that newly created account can be linked with the newly created opportunity. And after this, I can write OPP dot sorry OPP list dot add OPP. So here we have created this list. Here we have created this list. And in this list one by one, all the opportunities will be added. Okay, now after completion of this loop, if I want to apply null checks, so I can do so. So if OPP list is empty, and here I need to apply not. So if it is not empty, then I can write insert OPP list, right? So this way code is written. And here, like if I modify this, so what I can do, I can apply a check like whether account active field is yes, then only opportunity should be created. So that also can be done. So first time going to show you this implementation, I'm going to test it, then I will be modifying and will be putting one condition here so that you know like how in trigger we can apply condition like we did here. So here we applied if condition. So similarly here also we can apply. And here in this after insert method, we are calling or we are writing DML statement as well. Okay, so this way this create opportunity method is implemented. So now whenever I will be creating any account, so opportunity will be created and it will be linked to that account automatically. So right now I created these two opportunities. So here you can see sorry account. So here opportunity is not created. Now if I go and create new account, I am filling industry as agriculture. Sorry, April. So rating will be none. It won't change because if rating is sorry, if industries media, then only rating will be populated as hot. And here I'm changing active as yes. So now three methods will work. Now three methods, all three methods will be working because all three methods are part of this trigger. So first description will update, then rating will be populated basis on the condition and then opportunity will be created. So I'm just saving it and all the methods those we have defined will work. So here you can see opportunity is created and account name is ACC 4501 and our opportunity name is same. If I open it, go to details. So here you can see we are on opportunity. So opportunity closed it is today's date stages prospecting account is linked and opportunity name is same as account. Right. So this way automatically you can create records. If I go to details on account. So here you can see rating is blank because industry is not media and description is populated account is created. Right. So this way I hope you understood how I implemented after insert. Now I'm going to take your questions. So rather Krishna yes for opportunity method also you need to send ACC list because what is happening here from here whatever account record you are creating those account records will be part of this trigger dot new context variable. And from this trigger dot new data will be copied to ACC list because whatever number of contacts sorry whatever number of accounts you are creating all those account records will be available in this ACC list. And then one by one each record will be iterated here and one opportunity will be created. Right. So this way it is working. Okay. So Sachin is asking it is a good question. So it is like he's asking can you please reproduce the scenario where read only error pops up in after insert and how to fix this. So basically what happens if you use after insert. So in case of after insert this trigger dot new you cannot modify in case of after insert this trigger dot new you cannot modify it is read only. Right. But in before insert you can modify. So in before insert what happens we are just modifying this ACC list we are iterating on ACC list and we are updating it. Right. But now here if you update this account so you will get an error like this trigger dot new is read only and you won't be able to modify that. So for example if I write ACC dot and will revenue equals to let's say 100,000 if I write like this. So let's see what happens if I create new account record. So here you can see this error is coming record is read only. Right. It is on line number 12. So why it is coming because I am trying to modify this account ACC which is coming from this ACC list. So in after insert this trigger dot new is read only in. So I am writing it. So in after insert trigger dot new is read only. Right. So if you try to modify it here so it won't be possible. So this line number 12 you need to comment it is not possible and this is important to know sometimes by mistake in after insert we just modify this ACC list and you will receive an error. So you won't be able to do that. Now if you still want to update this account list because why we are not able to update it because it is already saved in the database. So if you want to update it you need to apply a DML. So you need to store these account records into separate list and then you will be able to apply DML operation on that. Right. Now if you want to apply some condition let's say if ACC dot active equals to yes then only you want to create opportunity. So this way you can write it. So I just modify the scenario. So on account creation if active field value is yes then only a new opportunity will be created otherwise not. So this you can implement and test yourself. So whenever you get time so just implement this scenario in both the ways. The way I demoed earlier and then just put this and create two records in one populate active as yes you will see a related opportunity will be created and in the another one populate no. So you will see a related opportunity won't be created. So I'm just moving to the chat and let me see the questions. Yes Nusrat in after events only we need to use DML operation because in before record is not saved to the database. So you don't need to use DML records will get updated automatically. So Shekhar is asking when to use child to parent and when to use parent to child. So it depends on the scenario. So maybe tomorrow when we'll be working with after or like update and delete triggers then I hope you will be able to understand it. So Sachin is asking for other scenarios. So what you can do just go here and here lots of scenarios are available. So you can just go and check and scenarios depend on the business requirements as well. Okay Praveen is asking to explain this read only thing. So Praveen I just explained whenever we create new records all the newly created record newly created account records will be available in this trigger dot new that we are passing as a parameter. So in case of after insert it is read only. So if we come here and we try to modify it like this trigger dot new values are available in this ACC list and ACC list is showing values into ACC variable. And if we update this ACC variable with some value. So this will give you an error because trigger dot new is read only and trigger dot new we are storing into this ACC list. So you won't be able to modify it. If you want to modify you need to copy these these records into a new list separate list and then you can perform DML operation. Okay. Okay. So session starts at 8 30 PM IST. So you can have this session tracker. So this session tracker link is available in the description of this video that you are watching. So you can have this link and here you will find everything whatever we have done is listed here. So these all are video links. If you go here so all these are recordings of past sessions and whenever I have sessions so I just provide the link here so that you can join. Yes, Vladimir. I find one guy who can teach integration. So soon I will be putting integration related stuff in the excel sheet. So that will be done. Next question. Shilpa is asking is it necessary to always check for required fields when we are performing any operation on after insert? No, it is not necessary. But if you are creating a record through trigger, then you need to populate values to those required fields. So shaker is asking can we use multiple methods in same class with the same name? So answer will be yes, but they should have different parameters. So here in our case, all the methods are receiving only one parameter. So in this case, method name cannot be same. You need to have different method names. Yes. So Revati is asking, can we create five to six records through anonymous window? So answer will be yes. And if you are creating bulk records, so we can use data import wizard, we can use data loader. So through that also you can create bulk record. From UI, you can create only one record. So next question is Greenarth is asking, can we make field is mandatory through trigger? So we cannot make field mandatory, but we can apply validation. We can apply validation through trigger for sure. Right? Okay, so this way I demoed you how we can implement before insert and after insert on standard object. Now I'm moving forward and I'm going to implement custom object. So on custom object, I will be creating trigger so that you understand. And before insert and after insert I will be performing and trigger I will be creating on position. So here you can see the first requirement says upon creation of position. So in our recruitment app, we created position object. So if you are following only the development related videos and you have not gone through that project, so let me take you to this excel sheet. So here you will find project related videos. So if you want to understand, if you want to understand these custom object related scenarios and want to implement, so you need to complete all these six videos so that you have that data model created and along with other features, then only you will be able to implement these scenarios in your org. Right? So requirement is upon creation of position, if it is a new position and open date min pay and max pay are not populated, then we need to populate them with below values. Right? So these should be the values in these three fields if they are blank in case of new position. So new position is basically a status status is a field and in that field this new position is a pick list value. Right? So we need to work on the same record. That's why we can do it through before insert. And next requirement is when a position record is created and status is new position, then we need to create a task and we need to assign it to the test user available in the org. Right? So these are two requirements that we need to fulfill. Right? So first I'm going to solve the first one, which is related to before insert. And in this before insert, we will be writing trigger on position object and this position object is a custom object. So with the help of this example, you will understand like how we can implement scenario where you will be implementing a trigger on custom objects. So jumping here under developer console. So here I'm creating new trigger. So I am selecting apex trigger. And here I'm naming it as position trigger. Right? So here I'm naming it as position trigger. And if I scroll down, so here I will find this. So here it is position underscore underscore C. So it is a custom objects object. That's why it is having underscore underscore C click on submit. So it is available here. Okay, now here I can write these blocks. So I'm just copying and pasting it. Okay, so I'm just removing these. And first of all, I need to implement before insert. So I'm creating a class now new apex class and its name will be position trigger handler. So this is an apex class and here I'm going to implement a method. So method will be public static void. Then naming it as popular data. And here we need to create list of position underscore underscore C. And I'm naming it as position list. So this way I will be implementing the method. Now here I'm writing position trigger handler dot popular data. And here I will be passing trigger dot new. Right? So I hope you are able to understand it, whatever I implemented here. So I just created a trigger. And in trigger I called a method and this method is defined in the trigger handler class. Right? So now what we can do we can implement a for loop. So position underscore underscore C POS colon, then position list. Now I'm iterating a loop on position list. Now I need to check. So let's jump here and open the position object under object manager. If I go to position object under fields and relationship. So here I will find a field as status if I open it. So here I will find pick list values. So here one value is new position. So if we are creating a position record and that position record status pick list value is new position, then only we need to do this operation. So here what I can do I can write POS dot status underscore underscore C equals to new position. If this condition is true. Now I can write if POS dot. So as per requirement next is open date. So we need to populate open date, but it should be null. If it is not populated. So what we can do first we need to check the field API. So from here I'm just having open date here it is. So in the code I'm pasting it if it is not equals to null. Okay, if it is null, double equals to null, then only I will be populating it. So position dot open date equals to system dot today. So this way you can write the code. Now again, you need to write if POS dot then next field is MinPay. So what you can do you can search MinPay here, copy the API name, paste it here if it is null. So you can populate value in MinPay. So it is 10,000 and copy and paste it. So here I need to use MaxPay. It should be 15,000. So this way here you can see this is our if block which is checking if status is new position. If it is new position, then I'm checking particular field. If it is null, open date is null, so date will be populated. If MinPay is null, then MinPay will be populated. If MaxPay is null and then MaxPay will be populated, right? So I hope this way you can understand. And Sachin is asking, can we club this if condition into first if? So in that case, you need to write it with and operator. So every time you will be using this with each if condition. So that's why this is first condition if it satisfies, then only we need to check because there may be chances open date and MinPay is populated, but MaxPay is not populated. This can be the chance, right? So whatever field is not populated, that field will be having this default value. Otherwise, whatever data user is populating, that will be available on the record. Right? So this way this is implemented now. What we can do, we can go to UI and we will be able to implement it. So here I'm going to search for recruitment app. So this recruitment app we created as part of the project and I already showed those who didn't implement that and want to practice on custom object and want to experience a project. So you can just go through those videos. I'm showing that again. So it is day number 16 to 21 because in development project, I will be having this admin project as a base and that admin project will be having all the use cases related to development. So it will be having flow related scenarios. It will be having apex and trigger related scenarios as well. Okay, so now coming to here and I'm creating new position. So since you all know, like in Salesforce, we have a job role related to cybersecurity. So I'm just naming it as position, then naming status, like status is new position and open date. So open date I'm populating. So open date I'm populating of previous date, like 1st of April and we set for today, that is 11th April. So we'll see whether it will update or not. And MinPay and MaxPay, I'm not populating. They are blank and I'm saving the record. So you can see record is created on details like open date is same, whatever we provided. But if you go and check MinPay and MaxPay, so we didn't provide MinPay, MaxPay, but they are available with the help of trigger. Right? So this way, if you have implemented a trigger, if you have implemented a trigger, so in the trigger or whatever code you have implemented basis on that, it will work fine. Right? So I hope you understood the requirement well now, how it is working. Now let me take some questions. So Sachin and Shaker, if you try to create method with same name and with same parameter, so you won't be able to save it. It will be a syntax error. Right? And trigger basically goes sequence wise, whatever you are calling first, that will execute first. So someone is asking like, Nikhil is asking what will happen if in before and after trigger when we import records using data loader. So they will work as is like the way we are testing them from UI or through anonymous window. So in the same way, they will be working on, like if you are upload, if you are importing data through data loader. Okay. So I don't see much questions because this is very straightforward. So I think everybody understood it well. Now moving to the next requirement and to understand this requirement, I just need to shift my location so that you can just read it properly. So basically the requirement says when a position record is created, when we are creating a new position and status is new position, then we need to create a task. We need to create a task record and the task record we need to assign to a user. It can be logged in user, it can be any user that is available in your org. So basically you need to pick that particular user so that you can assign that particular task to that user. Right? So it should happen upon record creation and status should be new position. Right? Here also status should be new position in the before insert. So what will happen if you create one more record? So let me create one more position. I'm testing the previous scenario and this time status I'm populating as pending approval and I'm leaving open date min pay max pay blank and I'm saving it. Okay. Position name is required. So I'm just populating it as test test trigger and I'm saving it. So it is created and you can see open date is blank, min pay is blank, max pay is blank. Why so? Because your status is pending approval. That's why it is not popular. Right? So we have one more requirement where if we are creating position status is new position, then we need to create a task. So task is another object. Task is another object. So now we have two object position and task, right? So again, it should be implemented through after insert. Right? So on the same trigger, I'm going to implement the code and task means like whenever you create any position. So here under activity, you will be having tasks. This is I think task. No, this is event. This one is task new task. So it will be created automatically. So on creation of task, you can see we need to populate subject due date, related to assigned to status, all these fields if we need to populate so that a new task record will be created. So whenever we will be creating a position, so here you will see a task will be created automatically with the help of trigger. Right? So I'm going to demo you that thing. So this is the method that I'm going to implement. Name is create tasks. So here I'm just saving it so that I can call it in the trigger. And in trigger here I need to call it create task and here I need to pass trigger dot new. So all the newly created records will be available in this trigger dot new. And this trigger dot new will be passed into the method method name is create tasks. Right? So this way trigger is created. And I hope you understood how to write before insert and after insert. And I added this. So here also I need to add after insert. If you don't add after insert in the first line, your code won't work. Now here I need to implement some logic. So first of all, I'm creating a list of tasks. So task is standard objects. So that's why I'm using tasks directly without underscore underscore C. And here I need to write position underscore underscore C with POS and then position list. Now inside this loop, I need to create task record. So creating its instance task t equals to new task. Now few fields I need to populate. So I need to populate few fields. So let me see what fields we need. If I create a task. So first we need subject, then we need due date. So here I'm writing t dot subject. So subject I am naming it as follow up. Right? Then due date. So here due date field is not populating. So what I'm doing moving here under object manager, searching for task. So we have fields and relationships. So here I'm going to search particular field. So first time searching for due date. So its API is activity date. So here I need to write t dot activity date. And I'm writing system dot today plus seven, right? So due date will be seven days after today's date. Okay, so this way I populated this field. Now moving forward. So next we need to populate related to. Okay, so I'm going to search it. So related to API name is what ID. So here we need to write t dot what ID. And it will be related to the position record. So we need to write POS dot ID, the newly created position that we have. So the newly created task will be related to that position. Okay, so now if I move forward, so here we have one more field that is assigned to. So here I'm writing t dot and assigned to means with whom you want, like to whom you want to assign this task. So to whom means the user. Okay, so if you want to assign this task to the logged in user who is creating a position, right? So what you can do first of all, you need to search this field assigned to here. So I'm searching it. So it is assigned to so assigned to field API name is owner ID. So what I'm going to do here I'm going to place owner ID equals to now here I need to pass logged in user information. So if you want to provide logged in user information, so you need to write user info dot get user ID. So it will give you the logged in user information ID of logged in user. So that ID will go to this owner ID. So the logged in user will become the owner of that task. And next we have status, right? So here I'm going and searching about status. So we don't have any field called status. So let me search it manually. Okay, we don't have any field called status. And let me see whether it is required or not. Yes, it is required as well. So maybe it will be available here. So t dot yeah status is available here. And here I'm going to put it as not started, right? So this way this task record will be created. So five fields we populated. And I hope you understood how one by one each field we need to verify whether it is required or not. And you need to search about the API name if you are not sure. And then you need to populate the values. Now what you can you can do you can write task list dot add T. So this T record that we created here will be added to this task list. Now after this loop, what we can do we can apply null check with task list. If it is not empty, then what we can do we can write insert task list. So whatever task record you will be creating, those will be linked with that position and they will be available on the UI. Right. So this way, this code is created and available in front of you. And I hope you understood how I implemented this code in front of you it is for custom object. Now here it is already called. So what I'm going to do I'm going to create a new position. And you will see a task will be created automatically. So requirement is status should be new position. And position I am writing as tester. And clicking on save. So both will work before insert and after insert. So before insert is populating open date min pay and max pay. And if we go to right side, so here you can see a follow up task is created. Right. If I open it, so it will be opened under task object. So here you can see it is task object. And this follow up task is created. It is assigned to me because I'm the logged in user subject is follow up due date is 1811 plus seven is 18 priority normal. It is by default. Okay, let me open it again status we provided has not started and it is related to the tester record. It is position record that we created. Right. So this way this task is created. If you click on this tester, so you will end up to position record automatically. And here you will see your task record available. Right. So this way, I hope you understood how we can implement trigger for custom object. So now what you need to do you need to practice all these four scenarios that I demoed you and you need to implement all these six scenarios as well. Those are available in this exercise sheet. So total six requirements are available. So first try to implement. And if you get stuck or you want to verify your answer, so just play this video and you can just verify. And these videos are containing apex test classes as well. So if you don't know, you can skip that part. If you know, you can try that as well. Okay, so this was all which I prepared for today's session. So I hope you understood whatever I explained to you. And if you don't have any question, you can leave. If you have question, you can just type that in the chat and I will be answering them. So moving to the chat. So Pratik is asking on updating child field if need to populate them on parents. Yeah, so update I will be demoing tomorrow. Today we are working on insert only. So in self relationship, it it will depend whether you need DML operation or not. So I think before so couple in this case, I think before we'll be working. Yes, Jana, we can use underscore underscore C in capital. It is case sensitive. Sorry, case insensitive. So I don't think it will break. So let me just check it. If I go here and write it in capital and save it, I think it should save. Yeah, because it is case insensitive, so it will save. Okay, Praveen is asking how we can assign tasks to other than logged in users. So in that case, what you need to do, you need to apply SOQL. So here what you can do create a user record and you need to apply very select ID from user where and here you can apply a particular condition. So you can just write username equals to this. So here you can write particular username or you can pick any other field like email, first name, last name, license, anything. So those those user records will be queried. If you think there are more than one record, so you can just create a list. And then through that list, you can just assign those users here. Okay, so right now what I can do I can just write U dot ID. So instead of this, I can write U dot ID here, because this you will be having that user ID that we are querying. So this way you can do this. So just try it in your org. And if you face any issue, so just discuss it in telegram group. So Sonu is asking why we need to create tasks. So Sonu it was the requirement. It was the business requirement like whenever you are creating a position record. So once this position is created, so for example, HR manager created this position, and HR manager is having a team. So from that team, HR manager want to assign this position newly created position to someone so that that person can follow up with the candidates. So that's why we are creating this follow up task. So that way this use case is available here. Okay, so I answered each and every question those you asked. And if you don't have any questions, so I can just end the session here. If you still have questions, so please ask and share the channel with as many people as you can, because we are about to start new bootcamp from 20 April that will be on cybersecurity. So if someone who doesn't want to make career in Salesforce, but want to make career in cybersecurity area, so they can be benefited. Yes, same we can do for profile also. So if you have any question, you can ask. So I am waiting for couple of more minutes, and then I will end the session. So Vamshi, we cannot assign multiple users as owner. User can be one. So Sonu, you're asking if we use this scenario for other record type means we applied it on particular object. So can you please elaborate more. So Jana, if you have Salesforce and cybersecurity knowledge, so in Salesforce, we have a job role, which is related to cybersecurity. Let me show you. So if you go to trailhead, so on trailhead, if you go to learn and career paths, so here you will find a career path. It is cybersecurity careers. If you open it, so here you can find all the details. So this is the role that I'm discussing. So if you know, so this is one more opportunity for you to work. So you need to figure out like how you can get a job. But if you have skill, then only you will be able to identify. So first learn and then you can. You can join this trailblazer community where security related trailblazers are available. You can discuss and know the things. So I'm just trying to open one more career path for you guys other than admin and development. Yeshilpa platform event I will be adding. And I think workbench is very easy so that we will be covering in the integration maybe. So Shrivali, you can ask that question in the telegram group. So Shilpa, yes, non ID people can try. If they are able to understand, then they can continue. Otherwise they can drop anytime and all the sessions are available free, of course. So there's no harm and duration will be like six to eight weeks and weekly there will be total three sessions so that on remaining time you can do some practice. Okay, so no, so for non technical position, you can just try and create a record. So right now I tried and created a position on technical, but if you do same for non technical, it will work same. If I select non technical position and create a record. So tester to and if I select new position, so same operations will be happening because we implemented code for object. We didn't specify record check record type conditions. So open rate is populated min pay max space populated if you go here. So you can see follow up task is also created for this newly created record. So Jana in my place, someone else like along with me will be taking those sessions. So Praveen configuration we do in Salesforce. And if you want to connect your Salesforce with any other application that is basically known as integration. Stella velocity Salesforce development is demanding that we do for industry related clouds. So you need to learn omni studio for that. So I'm learning that technology and soon I will do a certification for that. Then I will create recorded videos on that technology. And then after this bootcamp, maybe I will do live sessions so that we can discuss things. So Jana in six to eight weeks, you will get brief idea about cybersecurity. It is very large topic. So we'll see how it will go. How many folks joins if it is successful, then we can expand it into phase two. Otherwise we'll end up with six to eight weeks. Right. So I just need your support. If we have viewers, then only we will be running the bootcamp if no, then we won't be okay. So thank you so much for joining today's session and do more practice because today I gave you lots of exercises in the sheet. So just implement them so that you can become expert and be consistent and practice things. Okay. Thank you so much. See you tomorrow. Same time. Bye everyone.