Control flow execution with for and for-each loop

Salesforce Development Using Apex Control flow execution with for and for-each loop
14 minutes
Share the link to this page
Copied
  Completed
You need to have access to the item to view this lesson.
One-time Fee
$49.99
List Price:  $69.99
You save:  $20
€46.41
List Price:  €64.99
You save:  €18.57
£39.85
List Price:  £55.80
You save:  £15.94
CA$68.38
List Price:  CA$95.74
You save:  CA$27.36
A$75.69
List Price:  A$105.97
You save:  A$30.28
S$67.65
List Price:  S$94.71
You save:  S$27.06
HK$390.96
List Price:  HK$547.38
You save:  HK$156.41
CHF 45.35
List Price:  CHF 63.50
You save:  CHF 18.14
NOK kr542.95
List Price:  NOK kr760.18
You save:  NOK kr217.22
DKK kr346.22
List Price:  DKK kr484.74
You save:  DKK kr138.51
NZ$83.20
List Price:  NZ$116.49
You save:  NZ$33.28
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,484.79
List Price:  ৳7,679.15
You save:  ৳2,194.35
₹4,174.22
List Price:  ₹5,844.24
You save:  ₹1,670.02
RM236.85
List Price:  RM331.61
You save:  RM94.76
₦61,737.65
List Price:  ₦86,437.65
You save:  ₦24,700
₨13,903.63
List Price:  ₨19,466.20
You save:  ₨5,562.56
฿1,842.69
List Price:  ฿2,579.91
You save:  ฿737.22
₺1,612.90
List Price:  ₺2,258.19
You save:  ₺645.29
B$253.75
List Price:  B$355.28
You save:  B$101.52
R922.13
List Price:  R1,291.06
You save:  R368.92
Лв90.85
List Price:  Лв127.20
You save:  Лв36.34
₩67,969.88
List Price:  ₩95,163.27
You save:  ₩27,193.39
₪185.94
List Price:  ₪260.34
You save:  ₪74.39
₱2,861.35
List Price:  ₱4,006.12
You save:  ₱1,144.77
¥7,722.34
List Price:  ¥10,811.89
You save:  ¥3,089.55
MX$843.21
List Price:  MX$1,180.56
You save:  MX$337.35
QR182.28
List Price:  QR255.22
You save:  QR72.93
P678.57
List Price:  P950.05
You save:  P271.48
KSh6,648.67
List Price:  KSh9,308.67
You save:  KSh2,660
E£2,385.52
List Price:  E£3,339.92
You save:  E£954.40
ብር2,869.28
List Price:  ብር4,017.22
You save:  ብር1,147.94
Kz41,825.96
List Price:  Kz58,559.69
You save:  Kz16,733.73
CLP$46,485.20
List Price:  CLP$65,083
You save:  CLP$18,597.80
CN¥354.33
List Price:  CN¥496.09
You save:  CN¥141.76
RD$2,899.21
List Price:  RD$4,059.13
You save:  RD$1,159.91
DA6,716.85
List Price:  DA9,404.13
You save:  DA2,687.28
FJ$112.23
List Price:  FJ$157.14
You save:  FJ$44.90
Q388.45
List Price:  Q543.86
You save:  Q155.41
GY$10,455.72
List Price:  GY$14,638.84
You save:  GY$4,183.12
ISK kr6,977.10
List Price:  ISK kr9,768.50
You save:  ISK kr2,791.40
DH500.96
List Price:  DH701.39
You save:  DH200.42
L885.56
List Price:  L1,239.86
You save:  L354.29
ден2,861.59
List Price:  ден4,006.46
You save:  ден1,144.86
MOP$402.29
List Price:  MOP$563.24
You save:  MOP$160.94
N$920.44
List Price:  N$1,288.69
You save:  N$368.25
C$1,839.55
List Price:  C$2,575.52
You save:  C$735.96
रु6,679.37
List Price:  रु9,351.66
You save:  रु2,672.28
S/186.27
List Price:  S/260.79
You save:  S/74.52
K193.32
List Price:  K270.67
You save:  K77.34
SAR187.48
List Price:  SAR262.50
You save:  SAR75.01
ZK1,358.11
List Price:  ZK1,901.47
You save:  ZK543.35
L231.01
List Price:  L323.43
You save:  L92.42
Kč1,161.35
List Price:  Kč1,625.98
You save:  Kč464.63
Ft18,056.25
List Price:  Ft25,280.20
You save:  Ft7,223.94
SEK kr542.25
List Price:  SEK kr759.20
You save:  SEK kr216.94
ARS$44,003.90
List Price:  ARS$61,608.98
You save:  ARS$17,605.08
Bs345.36
List Price:  Bs483.53
You save:  Bs138.17
COP$195,270.45
List Price:  COP$273,394.26
You save:  COP$78,123.80
₡25,568.20
List Price:  ₡35,797.53
You save:  ₡10,229.32
L1,234.61
List Price:  L1,728.55
You save:  L493.94
₲373,712.67
List Price:  ₲523,227.64
You save:  ₲149,514.97
$U1,909.55
List Price:  $U2,673.53
You save:  $U763.97
zł200.30
List Price:  zł280.44
You save:  zł80.13
Already have an account? Log In

Transcript

Points same kind of thing in the coil statement if you see we are dividing these in three part, okay. So let me give more clarity on this in the while has to initialize part values, okay. Then if you see I checked the condition okay then I have increment or you can say, the increment of initialized when do I initialize some value to a variable that I'm taking here condition, then I'm gonna I'm doing increment increment. So all this initial is taking up on this on an increasing decreasing the value I'm doing in three different statements, three different lines in the follow what happened. Same while loop we can convert into for loop with one statement. If you go to follow statements, what happened, the syntax we used to Right like this so far, using the call keyword then all the three activity what you do here initialize check condition or increment decrement whatever it will do everything I like.

So past will do initialization here, okay. Then I can give my semicolon, okay, then then what I can do, I can do my condition check here, okay, then I can do my increment, or decrement like this, then I can write for the statement I want to execute like this. So, see this statement what I've written if I tried to convert to follow what I do here, I wrote four. Okay, so let's, I'm just going to print the count statement, simply writing instead of this. So now, initially my account is let's consider it cuarto one and I want to print for 1010 that means till the time count is less than 10. I want to print, see, if I see count equal to one, the past installation, whatever you did during Apollo during the while, then my condition check contrast and then condition and this one, so, simply I can write the syntax is going to be poor, my initialization, okay.

Then the condition check what do we do, then increment or decrement you can do count plus plus or count minus minus whatever you want. Okay, then insert this, you can write your statements whatever you want, right, same thing I'm doing here. If you see in the while loop, whatever I have, same thing I do to here. And if I try to execute these, you see, I'm going to get the same output, nothing but I'm going to execute this statement multiple times. I'm looping on the statement multiple times, till my condition matches Okay, so you pay go here. Let me take the do statement, say 123459.

Okay. Any questions on this tool? I know code Nemesis Rashmi? Yeah. Okay, so now the looping whatever I'm doing, I know, or 10 times I need to do, right. So, after 10 times this will look like Dude, I'll check count is one how it happened so fast my count variable is one okay then I will check one is less than 10 yes satisfied, then I will go on the exhibit my statement print one, then I will increment it.

So now my value will come to, then again I'll change this to less than 10 is, then I'll go into, okay, I'm offline completed then again I'm gonna increment my YouTube account What do I have here? Two plus one going to be three, then three, three less than 10. Concentrate, yes. Then I'll go on to entry like this and continue for loops. Okay, so now what are happening? And I know I'm just comparing within I know what is the complete Hello, but I want to compare you in the compile time or maybe the wrong thing I know.

Let's see. I'll give you one one looking statements. Okay, you will tell me how we're going to do it. Okay. So now very basic examples. Let's consider you have a big purchase of it, you have a Punisher so now what's going to happen on this one is there is one e where you got so many punches.

There is some kind of luck to you. All. Right, you got some funny jokes, okay. So now you have some levers for We're going to take the furniture from this lorry to your inventory or somewhere okay? they'll carry this this heading this way, but that means a up for you have to level okay. So, they are comfortable not to level one level take the example of one level.

So, what is going to happen this level will come and take all the furniture and keep in inventory. So, that means the taking of this furniture giving an inventory looking for that level that is multiple times in the same activity he can take all the furniture in a single store and even inventory he will tell you on day one. So, now see, when this lorry came or point this LLC truck came when this truck and so, does this the labor know how many punishers are there? We will have many maybe 10 maybe 20 maybe 50 maybe one also this guy that didn't know how many Time to lose nothing but can I say this guy didn't know this condition how much time this guy need to loop Am I correct? It may happen like this also. So now what happened?

So this furniture sold whatever thing we have is a collection of elements for me. Many elements are there so many punishers are there. So, he job go take we'll take all one day one and keep in my inventory till the time all furnitures not clear. So, go Come take this furniture, keep here. Again come take this furniture. Keep here.

Again contact this initial teacher till the time all the furnitures are not over. He will go and pick one buy one from the truck and keep inventory. We do like this America. minus your services. Okay? So whenever these kind of looping, we don't know how many times we need to execute the condition we don't know or we want to loop on each element or each item.

Then what do we do we can use something called for each something called forest. Like this power index a foster parent only, okay, we got to technically we call it as a foreach loop where you see the variable. Okay? And this is a statement here. Okay. So now it's my collection, then, is going to heighten my suspicions.

So see cataldo What are the cooks are not involved in this example what I said how many furnitures you are that collection, take one way one one element and process it take one column one furniture and even inventory that kind of example, in the time this collection not empty, continue make Excel okay? For example if I say okay in my app is the terminology let's say you want to process all case records off a customer Okay, so what do you do? See I didn't teach you how to get the data from database. Okay, I didn't teach you the collection till now we will cover in the upcoming sessions. But for example, I'm just giving you this see this one so you can understand that you can map how this happens. Let's consider this customer.

Now 10 cases one customer how many customer one up 10 cases For today or maybe in the month of January, you are having 10 k seconds but in the month of July he may have 100 acres in the case of 100 acres so now in the month of January when routing and routing only 10 days ago but when I'm looking at this I'm looking at the hundred cases for this I want to I want to look on each record and I want to process my logic on each record Okay, like Gary one furniture given inventories me carry one case the court process it carry with next case the court process it like that. Okay, so now, hundred k is nothing but my collection of records. Same way how you can do, let's see what we are doing on this example. Okay. So let's consider I'm writing one collection element, okay.

Don't worry, however writing, I'll tell you in the next session, okay. We have a condition we can discuss with this. Because in accounting system, let's consider, I have some colleagues on which I give as a list of integers. I will tell what it is okay? Let's see, it is my entire list. And I said, my new list of integers.

Okay. And on these, I will have many records, maybe 1020 3048 number of records. Okay. I'll teach you this completely the upcoming system. Now, I want to loop on this, what I can do, I am going to write what is my collection? My collection is at least always after the columns in Bowling will have the collision, then this collision contents what kind of data it's a person of integer type of data.

So my variable let's see, I would say is, okay, then you can process your logic. Let's see, I'll write my system to debug segment here. Let's see industry. I can do something like this. Okay? So let's see in your eyes, I didn't teach you anything about this just given the sample definitions nothing is okay.

So if you see this that means this is my collection, this is my each variable, then how many eliminate I have on this collection processes. So I'm not showing the output of this because I didn't tell you this collection and we're going to do anything here. But in the next little while I will tell this collections and I also know how this is happening, but this kind of look whenever a raid is called or a statement. So for each element of the collection, process the logic like for each case record or this customer process some logic, so that time when you want, I can go for college loop. Okay the Polish look, you can select this part, the variable part, then on boys collection, then my logic Any question della locals any confusion? Oh, this power for love.

And while while I hope is clear for you, is that correct? Okay, I'm not going more today, okay, these are the basics which we need to know before writing my program. Okay. And tomorrow we'll discuss about the collection, what is the least for the set or is the map, okay, that I can say next important thing in Salesforce objects to most lists that map. Okay, we'll discuss that in the next lesson. Okay, then we'll go to the core programming slowly.

These are the basic information is what you need, if you open to any crisis or anything in the world. You will see there will be mostly one if statement there will be mostly for loop statements okay any other variable declare the seven and a class everything will be there. Okay, so what am I missing you will see everything will be in Raul Davis yes Lucas? Just curiosity I'm asking just I don't know I don't I don't want to say don't Oh most of the times will not use violent do well right in effect Yes. See normally depending on the business requirement, so mostly logic whatever he will use this part is the replacement of oil you can use anytime okay. So, in playing that gas pod is our new oil scenario depending on scenario if weather condition you want to do something then you can be used to oil okay at least one time you want to do and this kind of scenario may fall very latest and go You may not see he do well.

Okay but it may be used, but since CE by you if this power see let's see consider I want to process my logic in this part whenever there is any case occur I want to process but if I will also say you there is no case occurred I want to do some other activities okay in my condition or editing I want to do something else okay. At least once I want to process is logic and then continue if my conditions are destroying if this kind of for the government comes then you pop the vocal to oil. The oil is not a replacement of oil or coal but for is that it really doesn't have oil for analog you can see for loop many okay and follow anybody will see maximum this one

Sign Up

Share

Share with friends, get 20% off
Invite your friends to LearnDesk learning marketplace. For each purchase they make, you get 20% off (upto $10) on your next purchase.