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
€47.51
List Price:  €66.52
You save:  €19
£39.57
List Price:  £55.40
You save:  £15.83
CA$69.83
List Price:  CA$97.77
You save:  CA$27.93
A$76.76
List Price:  A$107.48
You save:  A$30.71
S$67.19
List Price:  S$94.07
You save:  S$26.88
HK$389.07
List Price:  HK$544.73
You save:  HK$155.66
CHF 44.17
List Price:  CHF 61.85
You save:  CHF 17.67
NOK kr552.55
List Price:  NOK kr773.61
You save:  NOK kr221.06
DKK kr354.40
List Price:  DKK kr496.19
You save:  DKK kr141.78
NZ$85.21
List Price:  NZ$119.31
You save:  NZ$34.09
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.46
৳5,978.91
List Price:  ৳8,370.95
You save:  ৳2,392.04
₹4,225.77
List Price:  ₹5,916.42
You save:  ₹1,690.64
RM223.20
List Price:  RM312.50
You save:  RM89.30
₦84,012.69
List Price:  ₦117,624.49
You save:  ₦33,611.80
₨13,908.54
List Price:  ₨19,473.08
You save:  ₨5,564.53
฿1,733.10
List Price:  ฿2,426.48
You save:  ฿693.38
₺1,727.24
List Price:  ₺2,418.28
You save:  ₺691.03
B$290.46
List Price:  B$406.67
You save:  B$116.21
R906.09
List Price:  R1,268.60
You save:  R362.51
Лв92.91
List Price:  Лв130.09
You save:  Лв37.17
₩70,046.43
List Price:  ₩98,070.61
You save:  ₩28,024.17
₪186.68
List Price:  ₪261.37
You save:  ₪74.69
₱2,952.60
List Price:  ₱4,133.88
You save:  ₱1,181.28
¥7,718.58
List Price:  ¥10,806.63
You save:  ¥3,088.05
MX$1,017.02
List Price:  MX$1,423.91
You save:  MX$406.89
QR182.44
List Price:  QR255.44
You save:  QR72.99
P683.49
List Price:  P956.94
You save:  P273.45
KSh6,461.20
List Price:  KSh9,046.20
You save:  KSh2,585
E£2,482.03
List Price:  E£3,475.04
You save:  E£993.01
ብር6,237.86
List Price:  ብር8,733.50
You save:  ብር2,495.64
Kz45,607.24
List Price:  Kz63,853.79
You save:  Kz18,246.54
CLP$48,681.26
List Price:  CLP$68,157.66
You save:  CLP$19,476.40
CN¥362.01
List Price:  CN¥506.84
You save:  CN¥144.83
RD$3,017.61
List Price:  RD$4,224.90
You save:  RD$1,207.28
DA6,678.15
List Price:  DA9,349.94
You save:  DA2,671.79
FJ$113.48
List Price:  FJ$158.89
You save:  FJ$45.40
Q386.23
List Price:  Q540.76
You save:  Q154.52
GY$10,467.47
List Price:  GY$14,655.30
You save:  GY$4,187.82
ISK kr6,913.61
List Price:  ISK kr9,679.61
You save:  ISK kr2,766
DH499.81
List Price:  DH699.78
You save:  DH199.96
L910.32
List Price:  L1,274.52
You save:  L364.20
ден2,923.74
List Price:  ден4,093.48
You save:  ден1,169.73
MOP$401.12
List Price:  MOP$561.60
You save:  MOP$160.48
N$907.46
List Price:  N$1,270.52
You save:  N$363.05
C$1,841.10
List Price:  C$2,577.69
You save:  C$736.58
रु6,753.23
List Price:  रु9,455.06
You save:  रु2,701.83
S/189.86
List Price:  S/265.82
You save:  S/75.96
K201.41
List Price:  K281.99
You save:  K80.58
SAR187.67
List Price:  SAR262.75
You save:  SAR75.08
ZK1,384.62
List Price:  ZK1,938.58
You save:  ZK553.95
L236.44
List Price:  L331.04
You save:  L94.59
Kč1,203.80
List Price:  Kč1,685.42
You save:  Kč481.62
Ft19,537.53
List Price:  Ft27,354.11
You save:  Ft7,816.57
SEK kr551.39
List Price:  SEK kr771.99
You save:  SEK kr220.60
ARS$50,126.56
List Price:  ARS$70,181.20
You save:  ARS$20,054.63
Bs346.46
List Price:  Bs485.08
You save:  Bs138.61
COP$220,634.58
List Price:  COP$308,906.07
You save:  COP$88,271.48
₡25,407.49
List Price:  ₡35,572.52
You save:  ₡10,165.02
L1,264.30
List Price:  L1,770.13
You save:  L505.82
₲391,827.47
List Price:  ₲548,589.81
You save:  ₲156,762.34
$U2,138.81
List Price:  $U2,994.50
You save:  $U855.69
zł206.57
List Price:  zł289.22
You save:  zł82.64
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.