 Hello everyone. I'm Sanjay Gupta. Welcome to Sanjay Gupta Tech School. This is my website studiesalesforce.com, a video library to learn Salesforce. In this video, I'm going to demonstrate this scenario with the help of Apex. So we need to query account records created last week. Now we need to update phone number field of all accounts with this static value. Right. So in my previous video, I demonstrated you how we can insert new records or maybe new related records. Now in this video, you will understand how we can apply update DML with the help of Apex. So jumping into Salesforce or developer console. So here I'm going to implement a method public static void update account phone. So method name should be relevant like whatever operation you are performing to the method. So name should be relevant and it should apply proper naming convention. So first word will be always small. Second word on onwards first letter of each word should be capitalized. Now here we need to apply SOQL. So again, like we did in the last video. So in this video as well, I'm going to test SOQL here first. So the requirement says we need to query account records created last week. So here instead of this year, I need to put last underscore underscore week. Clicking on execute. So here you can see total 13 records are available. So now I can copy this SOQL and I can use it in my code. So I'm going to create list of account ACC list equals to here I'm putting this SOQL. So returned result will be available in this ACC list. So after this, I need to check it for null. So in previous video, I used size in this video. I'm using is empty. So if ACC list is not empty because I use not. So if it is not empty, then only this if condition will be true. Now I'm applying this for each loop. And it will iterate on this ACC list. Right. As in previous video I demonstrated, we can use this SOQL here directly. So that is also possible. So after implementation, I will show you like if we copy and paste this SOQL here. So what all changes will be required. So now we need to update the phone so we can simply write this. So I need to put this value. Right. So this is the ACC list and through this ACC list. One by one countercords are available in this ACC. So if we update this ACC, so it means this account list is updating automatically. So after completion of this loop, you can simply write if and you can copy this here again. And you can write update ACC list. Right. So this way this code is complete. And if we execute this code, so all the countercords which are created last week, their phone number will be updated to this value. So now jumping to anonymous window. And I'm going to call this method. I'm executing this so it is executed moving to accounts. And here you can see I'm clicking on new last week, and all four numbers are updated with 1234567890. So it is a dummy number. So don't try to call on this number. So I just use this for demonstration purpose. So if what if like we use this SOQL here, if we use this SOQL here, so in that way, like we can't use this ACC list directly here for a nation. So we need to create one more instance of account list, then we need to add this ACC into that list and then we will be able to update that. Right. So let me create that new list of account. Right. And here this is not required. It is not required. So we are wearing accounts and those will be available into this ACC. Now, I need to use ACC list dot add account. Right. And then I can check this here. And this time like I am changing its value to 123456 opening anonymous window clicking on execute. Let's see what happens. So if I click on accounts again, move to new last week. So you can see phone number is updated again. So this is another way like if you use SOQL in this for each. So you need to create this list and then you can add records into this list and you can apply this condition. Right. So in previous scenario, things were different. So we didn't require this additional list because we were creating opportunity. So here the account records which we are creating, we are updating those only. So for that purpose, we need to do these additional changes. So I hope you understood both the implementations and you might have understood like how to use SOQL how to use list how to iterate list with for each loop. So I tried to implement the use case with proper example. So if you understood this so you can watch more scenarios, those are available in this playlist. So so that you can understand other scenarios as well. And study salesforce.com so visit this to watch more and more videos related to Salesforce. Thank you for watching this video. Have a good day.