how to create constant and what is type conversion

Salesforce Development Using Apex how to create constant and what is type conversion
18 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
€48.10
List Price:  €67.35
You save:  €19.24
£39.88
List Price:  £55.83
You save:  £15.95
CA$71.97
List Price:  CA$100.76
You save:  CA$28.79
A$80.16
List Price:  A$112.23
You save:  A$32.07
S$67.96
List Price:  S$95.14
You save:  S$27.18
HK$388.27
List Price:  HK$543.62
You save:  HK$155.34
CHF 45.02
List Price:  CHF 63.04
You save:  CHF 18.01
NOK kr569.59
List Price:  NOK kr797.48
You save:  NOK kr227.88
DKK kr358.90
List Price:  DKK kr502.49
You save:  DKK kr143.58
NZ$88.63
List Price:  NZ$124.10
You save:  NZ$35.46
د.إ183.61
List Price:  د.إ257.07
You save:  د.إ73.45
৳5,972.19
List Price:  ৳8,361.55
You save:  ৳2,389.35
₹4,258.89
List Price:  ₹5,962.79
You save:  ₹1,703.89
RM224.30
List Price:  RM314.04
You save:  RM89.74
₦77,378.02
List Price:  ₦108,335.42
You save:  ₦30,957.40
₨13,924.71
List Price:  ₨19,495.71
You save:  ₨5,570.99
฿1,707.62
List Price:  ฿2,390.81
You save:  ฿683.18
₺1,762.36
List Price:  ₺2,467.44
You save:  ₺705.08
B$310.08
List Price:  B$434.14
You save:  B$124.06
R926.14
List Price:  R1,296.68
You save:  R370.53
Лв94.05
List Price:  Лв131.68
You save:  Лв37.62
₩72,995.06
List Price:  ₩102,198.93
You save:  ₩29,203.86
₪183.24
List Price:  ₪256.56
You save:  ₪73.31
₱2,921.84
List Price:  ₱4,090.81
You save:  ₱1,168.96
¥7,853.11
List Price:  ¥10,994.99
You save:  ¥3,141.87
MX$1,006.35
List Price:  MX$1,408.98
You save:  MX$402.62
QR182.19
List Price:  QR255.09
You save:  QR72.89
P691.26
List Price:  P967.82
You save:  P276.56
KSh6,461.20
List Price:  KSh9,046.20
You save:  KSh2,585
E£2,544.49
List Price:  E£3,562.49
You save:  E£1,018
ብር6,361.91
List Price:  ብር8,907.19
You save:  ብር2,545.27
Kz45,590.88
List Price:  Kz63,830.88
You save:  Kz18,240
CLP$49,514.09
List Price:  CLP$69,323.69
You save:  CLP$19,809.60
CN¥364.84
List Price:  CN¥510.80
You save:  CN¥145.96
RD$3,032.23
List Price:  RD$4,245.36
You save:  RD$1,213.13
DA6,760.37
List Price:  DA9,465.07
You save:  DA2,704.69
FJ$115.98
List Price:  FJ$162.39
You save:  FJ$46.40
Q385.05
List Price:  Q539.11
You save:  Q154.05
GY$10,455.66
List Price:  GY$14,638.77
You save:  GY$4,183.10
ISK kr6,980.10
List Price:  ISK kr9,772.70
You save:  ISK kr2,792.60
DH502.81
List Price:  DH703.98
You save:  DH201.16
L922.32
List Price:  L1,291.33
You save:  L369
ден2,959.81
List Price:  ден4,143.97
You save:  ден1,184.16
MOP$399.96
List Price:  MOP$559.97
You save:  MOP$160.01
N$920.98
List Price:  N$1,289.45
You save:  N$368.46
C$1,839.04
List Price:  C$2,574.80
You save:  C$735.76
रु6,810.12
List Price:  रु9,534.71
You save:  रु2,724.59
S/186.41
List Price:  S/260.99
You save:  S/74.57
K202.74
List Price:  K283.85
You save:  K81.11
SAR187.78
List Price:  SAR262.91
You save:  SAR75.12
ZK1,383.10
List Price:  ZK1,936.45
You save:  ZK553.35
L239.36
List Price:  L335.12
You save:  L95.76
Kč1,209.95
List Price:  Kč1,694.03
You save:  Kč484.08
Ft19,835.61
List Price:  Ft27,771.44
You save:  Ft7,935.83
SEK kr553.09
List Price:  SEK kr774.38
You save:  SEK kr221.28
ARS$51,277.48
List Price:  ARS$71,792.58
You save:  ARS$20,515.09
Bs346.08
List Price:  Bs484.55
You save:  Bs138.46
COP$219,391.32
List Price:  COP$307,165.41
You save:  COP$87,774.08
₡25,377.51
List Price:  ₡35,530.54
You save:  ₡10,153.03
L1,269.45
List Price:  L1,777.33
You save:  L507.88
₲390,156.27
List Price:  ₲546,250
You save:  ₲156,093.73
$U2,225.52
List Price:  $U3,115.91
You save:  $U890.38
zł205.57
List Price:  zł287.82
You save:  zł82.24
Already have an account? Log In

Transcript

In the previous lesson, we discussed what is this class and how to clear the data members and the how to create the class methods and how to create the object of it, and how we can call the different method using my object. So this was concepts we can see a different type of data type called supported by Salesforce that we have seen. So now today, we'll discuss more conceptual topics like we are going to discuss about what is concerned in Salesforce, like in our test, in writing, how I can create a constant variable called Can I can say I can say, what is constant, okay, and how to manipulate the expressions. And we'll see how to use the conversion. I'll talk about each one each individual topic one by one, and we'll see how we can use the control flow statements. Do the very basic things we'll discuss.

And we'll use these basic things in accounting systems. So see, in the previous example, when we did I disclosed when I want to create a variable what I need, I need a data type and my variable name, then optionally, I can assign some value to it. Am I correct something again, then I can assign. So now like, if I want to declare integers, number four, they do. My data type is integer. Let's see, variable name, I gave us a number.

Then I want to assign some Hello, I say Dustin, okay. And again, I can write some more logic, some more logic I can write okay. And after writing again, if needed, I can set the value of this variable to 20. Also, again, same way, I can write many more logics again, my programming you can write again, I can say it variable value 215 also see the variable number initially had value 10 then I said to 20 then I said to 15 Okay, this will be what I'm reading. So now let's see I want this variable whatever I have I want this variable value should not be changed, okay, should not be changed after initialization of it. If they want to like this, what will happen?

But what Okay, let's see, I have I want to like this I want to create an integer variable, nothing but number and I didn't set any Well no, I wrote some piece of logic and writing some dummies that statements in the form of some logic, and then I'm going to say it number was 10 for example. Now again, I can write some logic and wherever you go, again, you are not allowed to update the value of this one. So if you want this kind of Then we can go for constant we have declared the constant how we can declare the constant. So, whenever you want to declare any constant, simply what you have to do, you have to use one keyword, which we call constant. Okay? constant you would have to use.

So if I want is integer number one to be convert to constant what I have to do, I have to write like this, okay, sorry, it's not constant, I have to use keyword final. Okay. So what I have to do, I have to define final integer less number. So this is nothing but a number variable of type integer, which is final dice. So, that means once I set a value to it, I cannot add any more values, but I cannot update the values. Let's see how it's going to happen.

So, I'm in the writing I'm in the sulfus. Okay, I'm going to open my Developer Console, you can use any IDE Whatever you have, you can use your Visual Studio code. You can use your poster, comm ID or Developer Console, or any way you acida you like this. Also, you can use whatever ID you want you can use. For our example, I'm going to my Developer Console. Okay?

I'm just going to write some piece of anonymous code. Okay, as I said, I'm not going to save this code, simply I will execute. So anyhow, in upcoming session, I will explain what this what this Developer Console going to do for us. But for now, I'm going to write some piece of anonymous code. So I went to my debug. From here, I open execute anonymous window.

So I'm just holding everything here. But what I want, see if I want to create a integer, I just specify here, integer number equal 10. Then again, I get let let me make a statement here to debug any messages. In the log file. I can print like this. Okay.

Try the system to debug, then I want to see what is the value of number. Okay, now let's see, I don't have any value. So now what I can do, I can come here, then again, I can set the value of number of skin. Let's see, I want to set so that base image after fast insulation, what is the Hello coming here? See my number. For now say, Molly.

I'm just going to in update this number hello to something else. So say he may update the manual is going to be 20. And he may say after a second initialization, the hell is 10 or 20. What is the hell do I have right now? So is this a one to operate or not? That's a second initialization I was just going to do going to do it.

For now I'll see. If I go and executed what is going to happen and I'll see in the log what is happening. So I have declared one number variable of type integer and in there I have said value 10 and then I have silver boundary. That means once I initialize a value, and also I'm trying to automate, so say it's a normal normal variable who to declare for now either a goatee operator, obviously nimbo number is a number. No, it is not like this. It's a keyword.

Let's see, I'm just using like this. No, it's my fault. Okay, see. So other keywords you can use as a variable name, that also you saw here. So you have to use non keyword words to be declared as variable. Okay, I click on execute my this piece of code executed, we'll see parties coming on my log file.

I open my developer console here. Then I click on my debug only statements. See, initially my value was null. You can see past I don't have any value assigned to number variable. No, but I've been so in a print they say no, the value is coming along. It's nothing There.

So now I assumed it was 10. So you can print it, you can see Ellucian you can see the statement passed in is an insulation number 10. And again, I initialized or you can say I modified the value to 20 with the same variable, I'm just updating the value. So now they're looking into 20. So see, now that means I can modify the value again and again whenever I want, if I want, okay, now, once you initialize, you are not allowed to modify. Simply I have used the keyword callers final, something I wrote.

Finally, it's a keyword. So I define the solar panel. Now if I try to Google what is happening, see, it swings an exception is system final exception. Final variables already been initialized. That means you've seen you have been already initialized hello to my final variable. Up on this document.

There is a final variable to declare cause Name is no number. So I have initialized the number Hello at line number three. And again, I'm trying to initialize or trying to update the value on line number five, so it's not alone. So, I cannot I cannot have this piece of code also, or I cannot run this piece of code. Because final variable, you can insulate only once. You see, I just commented this line code, and now I'm trying to do it now I'm successfully able to do so, once you initialize value of any final variable, then that became constant.

So no nowhere in the same transaction can be updated by any logic or body nature, the value of this variable Is this clear? This is basically recall constant if you want to declare any constant, then you can declare like this. Okay. I saw you know, coming to sort of I know take a examples of writing trigger or any of this. Let me let me For you, how am I going to use this final constant variables on my program? Okay, just now understand the concepts Manasa look at any question on this content but you're no devices.

So only thing one thing right? So we never use the phonetic keyword the variable becomes constant constant till it will allow only to initialize one see I have initialized here alone. And in the point I declare I didn't set any value. That means I didn't initialize anything. If you see this program we run right now it is executing. It's fully integrating, but see if I initialize some value here now and again also the insulation statement of same variable on line number three, if I try to execute Okay, it's not alone.

So only one time in insulation can be done. Only one time you can insulate you, this same variable up for the final or you can say of constant variables cannot be detail is multiple times Okay Okay. Perfect for now see okay let me any question from this part already see here Okay, that's fine okay I think it was not able to hear us in spite of noise. So you understand what is the construct and in the construct we understood okay? The variable whose value do not do not change after being initialized that we call mine constant variables. Okay, I'm just giving this note for you, so that I can now share with you okay.

So you can can use you know, when you practice or when you want to refer you can you can use this notes Okay, I'm just giving you Okay, perfect. So we understood how I am going to declare any constants or any a variable called Hello cannot Be more prepared after being incentivized okay. So, now, if you remember in the previous session, we have discussed many datatypes let me show you that we have discussed like my blog, my Boolean my date or integer long my things, okay. So now whenever we have many data is what is going to happen, let me see something like conversion how this conversion going to work? Okay. Now by using the conversion rules, see, I have this is again the basic concept which we need to know for operating systems.

Let's see, I have one integer variable, let's see, integer number on every integer number one. Okay. I have some ello, which we'll call 100. Okay, and also I have another another variable double CD numbers. Okay, and I want this number one should be copied to number two. Okay?

So nothing but my number one is one. And also let's see, I have one belt one variable called string and the letter C i said str one point I stoled something like sensors. Okay. So can I stole the str at one value to my integer type of variable? If I have one more integer? Let's see.

I end one. Can I store my SPR one there? It is, hose. hose value is stored in SQL one variable. Can this str str one can be initialized to integers? No, no because was as I explained in the previous lesson, what I said it's basically it can store the same type of record.

So now being the st wanting a string type I am not able to assign an integer, but there is also some kind of conversion rule. So, what you can do, if you want to convert one type to another type, what kind of things we can do what kind of things we need to consider, for example, this integer number and I have double, but double can store hundred Also, I'm incorrect, nothing can So, number one here. So, not double or long can take my integer value also, when I say let's consider I have one decimal point, can I define in decimal number equal to hundred? Is it possible or not? is we can is that means this hundred nothing but my initial value correct. You see there are some some something which we can automatically assign interior to the female I can do or My integer double also we can do so what I'm trying to say here whenever you have this kind of thing.

So, the variable of lawyer type I will define what is a lawyer type variable of lawyer numeric types can be I say into my higher type without any explicit deconversion Okay, there are many methods which I will talk in upcoming sessions they are tangled giving you basically copied Okay. So now, when I say lawyer, I'm just giving the sequence of the lawyer integer is my lawyer numeric type after integer my entire is nothing but long Okay, like though these are primitive datatypes what we have listed out in the previous system, okay, then same way I have double, then I have decimal okay. So see any deserve a low you can assign too long automatically the integer is a loyal loyal part long can store an integer and also long can be stored in in in double and any double can be stored in decimal without loss of any data.

So, now in the integer if I have 100 that hundred can be stored in long also okay and that double can be stored in that Canvas and that hundred can be stored in the same way if you see it has a long part if I have some long integer okay drama. So, can this be also if this long integer it cannot eat may not store an integer, it may not fit in the size, but obviously it will fit in the double and also it will teach on the decimal also. Okay, so same I even go to double Okay, let's see Something like this or you know, okay. So, in this double value what I have it can be easily accommodate to my decimal value okay without any explicitly cumbersome simply I can assign like this, okay, but the thing is I try to assign my decimal value to integer let's see our let me make little small 123 decimal six seven, if I have this kind of value, Okay, can I store this value in integer, if I am going to store my decimal point is going to be truncated going to last somewhere.

So I cannot store 1.3 3.67 in manager manager can store only one policy method. So that means if I try to convert from higher type to lower type, then we may have lost the loss of data. Okay also very low. So if you see in the decimal I have I can still one to a punch even if I try to convert that to integer I may have only 123 Okay. So, I will say there are many methods on each type of integer arithmetic class for us, there are many methods how we can convert from one type to another day. So, now, what are the basic what I'm saying we can convert one data type to another type, there are some types which are known for is no need of external conversion method we can explicitly convert by assigning from lower to higher.

So, if I have an integer variable number one that can be assigned to double simply by writing a extrusion statements like this number one can be assigned to a double variable. So, same way any lawyer type can be assigned to a higher type explicitly okay and he will try to assign any higher type loci, it may lose some data, I will show you how we are going to assigning all these kind of things, okay. So when you go to each individual classes that might show you how we're going to do it. Any questions along the way? Minus, trust me. I'm good.

Thank you. Yep, perfect. Okay, so now we are going to

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.