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
€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

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.