Exception handling in apex

Salesforce Development Using Apex Error and Exception in salesforce
42 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

So, today we're going to discuss about the exception. So what is JSON? parsing? We need to know what is exception. Okay. Why exception occurs but yeah actually last resort we're talking about custom setting we are done with the yeses without some example and a very small okay.

So today discuss projects are fun. Our exception occurs in the application, if any exception then how to handle the exception. Okay. How to handle exception in Africa Okay, types of exception and some workarounds and some examples to discuss. Okay. So parsing in the room telling pottage exceptions what you understood if somebody last interview concurred, tell me in your project with somebody.

So, whenever you are writing any piece of code, that piece of code is your logic, right? You're like a gym. I'm just going to write some piece of code here. Like I'm going to open up some class that class I will take in medical groceries or some electrical diskless. Yes, Alexandra Yeah, yeah, that Adam. I'm just writing a small class.

Let's see what's going to happen. Whenever I think a class, I'll write my own logic. So I like to something tests to assume I'm just writing public class. Okay? So imagine I wrote sample exception. Okay?

So here, if I have any syntactically any song, any error, that instead of public, if I write p UB, I LC, something I wrote exposure, some method I'm writing it, if there is something texted or immediately I'm getting this error message when saving the record for it 24 seven class. That means it's, I'm trying to tell if there is any syntactical error or body hog, all the error, I am going to get incompetent. Right? So, secondly, if I don't have any syntax errors, Okay, I have writing population or sample exam, some sample sample example. Okay, there's some class I have exaggerated. So here what I'm trying to do, I'm just trying to divide two numbers, integer array comma, integer.

Okay, so here I am just in type I'm writing an integer. Here, I'm just trying to divide two numbers on dividing a by b. Okay? This is my complete class. This classy I don't have any error in this class. The nominal class is going to say perfectly, but it isn't.

So now, I'm going to put this class so far, never been a good start. That nothing but a long time. Pay 1877 first load me I'm just giving this example on political something. Okay? lesson scepter Yeah, no, I don't Just trying to execute this class, I will just try to call this class method and we'll see what happens. So I just cleared the object of this idea of the object reference name.

Okay. And now I am just going to call the method what is the method? Is it fisherman's prefer operator extended introduction I'm just kidding the Ethernet debate okay. We did not divide. So here See, now, I will pass it Hello as 10 and this is going to return me an integer value. So I'm just adding in the integer return.

Okay. And here. I'm just printing it. Okay, so sorry, I don't but I haven't been. Let's see under security when a good tenant to follow a path to the class method and class method logic is going to execute. And I am going to get the output, correct.

Yes. So now, my program is running so fine. Okay. Let's see no input what I entered in the wrong time, is calling that method and executing all the logic for it. I 10 by two, I can help you I got it. Yes, sir.

Now let's see. I'm just passing on a window in passing in and do an activity. Oh, some extra time coming through. Yes. See, syntactically my program is correct. Yeah, but Logically, there is some wrong way or in runtime when I'm trying to execute the program.

There is some wrong or error occurring by learning while running the program while ignoring the program, but there is to the compile time and runtime whenever you're writing the program and saving the quarterly compile, and then the court will say that correlation, one score is saved whenever executing that scenario will come around time. So see before compiled time for error getting that is simply I can call as a compile time error or simply error. But once code is saved, and finally executing the code, when running the code, that time if any error coming, that one we can call as a runtime error, but yes, runtime error is nothing but excessive payment. Yes, honestly, excellent. All right. And what is compile time?

Whenever I wrote this code and I said I'm in what we call the compile time errors is normally called error only nothing earlier okay. So, this is called a custom code. So, now that you are a user Okay, you are just trying to divert to number you will get the system but metrics and what you understood nothing correct. So, now, whenever the exception occurring, I should handle it correct, so, that users should not get a wrong error message or some big message for who should tell Okay, there is some some problem with looking on this or some message you can throw there is a no. So, this is the exception exception, usually runtime errors. Okay.

So, whenever x isn't occurring in the application, we need to handle that exception. Right. That means the runtime error occurring, we should handle it By accessing a course in application, because there is some logical is some error is there in all time which is open. So, we need to handle the exception. So, that means whenever any exception according in your application, your application sooner class or applications will not stop the user to. So, to process that the applicants would be here as you said normal error it can contain some other work there.

So, we need to handle that exception in such a way. So, how can we handle that okay, we handle the Excel zone what happening is any error occurring or anything occurring. So, we need to be recover from the recession. Because see now, in this method, some extra data access to who can serve a call the method it can be here. So, instead of throwing the excess on from this method to the calling method point I have a call method c i call the divide method here. Third is going to the class here a certain occur the accident zone to the place where a call the corporate isn't.

Yeah. So now, what I can do here, I need to handle the throwing of a system from the method in the method on accident occurring. It's throwing to the calling method calling class or calling plus. So I need to handle their third party thing to handle the exception. We have something called try get an Angular. Okay.

Something we have try. Catch, finally. Correct. So what is doing this blog can be used to recover. I'm Tony When I was going from that method to this method, so I need to contend that existence here. So, how can I write this try catch block.

So, what does index index of this if you are expecting some code in runtime going to throw the exception what you can do is you can put that piece of code in the try catch block, write a try block, right here you write your logic. Right, which you're expecting for access on in runtime, particularly may or minor depends on the party included into the insert. Now, whenever the exception occurred here, indexes on to go here we have one cache block that means I am going to catch the exception part occurring in this try block. In this block, even exception occurring, there is somebody ready to catch that exception. Okay because what occurring here This request right here here we can mention of what type of exception these catch block can handle can throw can get it Okay. Okay.

So now it will drop Finally, here. Now two things. So, now let you wrote some logic in the try block, okay. So in the try block exception occurred, an exception occurred immediately the catalog came to here. So if any exception occurred, then this catalog is going to be good. I may have some logic here some piece of code again I'm writing here, but isn't there whenever any code inside the try block throwing the exception that exception will be cast by cash flow we may have multiple cash no okay.

The cash flow will actually based on what type of accidents will indeed and so what exactly it is then that logical input. So if there is no exception occurring then this block is going to execute on No, no. Okay, if there is no accident occurring, then this catalog econ blog is all going to do. Okay? Yeah. But I have another blog called the painterly effect doesn't occur or not.

It not matters. Okay. Ignore matters utterly Jason according but always this finite lock code will execute. Okay. Okay. Honestly, yeah.

Okay. There's nothing on the show. Okay, we'll take a walk going back and see the additional thing I explained. In this return a and b. Some exception may occur, okay. So what I'm going to write here, I wrote a try block.

So now, in the try block, what I'm going to do here, I'm just writing one catch. Okay. Let any type of accent Something I would access and yes there are different type of lesson okay. So, here I am just trying to do something or when a story I can call some other logic so I just writing here something exception occurred are these things isn't something the system debug exception occurred or the exception that accompanied message but to not display okay. So there is also we have finally method which is a complete not compulsory here see if I don't have final material so I can work around it, but I just do this one thing that I just make a habit. Okay.

So I somebody to return segments with their bigger integer type. So out of this, I'm just writing return something like that. Okay. A lot of time writing finally will execute. Yeah, whatever do they finally blog, like you said, now I have the only tie and catalog. To see I'm just going to here, I'm entering the same code.

What am I going to get any exception? No, not at all third. See, I wanna click the good deed I created a system. I didn't get in a second third. But even after that, taken care by that catalog, only then that Cash Flow code is executed. See what you can see my execution of top bar see it's one, that math exception occurred because I thought this catch block within a system under development isn't before either I don't have this with this one exception flowing to my calling method calling class there I saw that directly occurs when I am not able to execute that program.

Now I'm able to execute that program. But the exception is tracking in application but it's not stopping the user to be able to perform some the test code. Okay, so we did finally segment or sigh may we'll do it right. So, if you will write your final statement, assertion occur or not. That final segment will be here, as if I'm just writing a final statement. Everything is under debug And here.

This is a final mock. Okay. Okay, I'm just telling you to think I'll pass the positive value, and I'll pass the negative value. We'll see what's happening. Okay. So go to developer console.

I want to use dnn two. Okay. And just including understanding or not. Yeah. Whenever including it. Yeah.

This is the final block intuited and challenged by the paper. Yeah, noise there's an upward angle log into the paper. In the same time, even it couldn't occur. Then do a pass the fantastical let's see Right can also kind of block camper. So I am trying to tell if he were exigent occurring or not I don't care Neha anytime my final blog is going to do okay yes here I have a tribe lock well under dividing each one we've had trying to divide the number zero is going to throw a method yeah yeah, I hear I don't know man he was he said need to return some value. So I'm just writing here.

You can Not nothing, we'll go see. If there is I just wrote for this, if you want you can define one variable here. Normally integer. Okay. So here you can have these in ID is equal to A B. And again, right it's an idea, right?

So no sending God I don't want to declare variables. There's nothing that Nala will pick up. Otherwise one blank resolution understanding. Yeah. So now you understood how I'm going to handle the blocker. Right I need to write, try, catch finally correct.

So I never any accident occurred. That exercise will come to the gas boiler then I'm going to educate Get lock logic then even a pseudocode or not Anil blog is going to do well okay okay like this if you have a very big class what we have written in class everything we can put in a certain block we can have to have a try block catch block and we can do it same the same time we have also one statement all other statements Okay, some third statement we have this first segment for doing further efficient you got you want to go to the following class that time you can use this to a system or tonight he is arrow who excels at agile now in the program one exception upper okay so data has only one so far do you like it or or who? Okay record on me that yes, it will do close Yes, the class which calls this method that class is going to get that callback from Kurt he or we didn't write that one before we don't have this problem.

We didn't I forgot the title it's going to the calling method. In this Mr. Evil you want to throw something we can throw here. So here let us jump here. Now instead of different this one, I can throw th R or w tau, but also I will throw one ackerson for like before I'm getting the math exam card number you do something they did they just really okay. I'm not gonna go on.

Honestly. Yeah. Can only Chronicles on time. Music Based on my level need a certain type of intro, so what else is on them? Like that we have to do. Okay.

I enjoy exorcism class. Oh, yeah, I totally in category has the exception and we can do our user defined. Yes, yes. I can name the throw on the same thing. Yeah. Yeah.

Tempting, can we get up? Same all the stocks are the same thing, right? Nothing differently there. Okay. A lot of things for you now. Okay.

Also, again, writing our own a person blog also. We'll see how that One excellent blog also again, there are a lot of titles are there things that I can relate to then at line 10? custom class, I'll call this one. Okay. Company I'm trying to tell, we can throw that into some some here. Okay.

So now there are we have different types of exceptions. Okay, because I'm talking this is memory some time you saw this list of cursory math isn't quite. So when writing the lease sometimes on all pointer equals one, remember? Yeah, sometimes we're saying DML Excel sounds like that. We have different types of equipment. Okay.

There are a lot A lot many types of different, we can tell something called as a DML or DDL or DML statement, like whenever including some DML statement, maybe your insert or maybe your update. By default the DMS had manual pivoting, okay. If you're inserting or inserting the record, if you will miss one record in annex one will occur. So not for any DML language you will getting this for example, during in 30, if you miss any required field or so, no. Yeah, in the same time I have something called least because we all are in law and law learning the least for you if you have any problem with me. please type them into distance.

So, see, sometimes you will see whenever you want to access a list variable where the index is not exist, let your list contents for 11 What do you want to assess a filament or 711 for 11 the index is not there in the list what you are trying to assess. So, one exercise right yeah gotcha thing on index out of the bone okay. If I'm not in the same time, we have not appointed a system not Failing whenever you have a variable okay in the variable you don't have any value what you are trying to get some value from that variable that time no point or a person income okay the problem with a variable with a D referencing a variable okay? We contents that are just one variable content and all the body we're trying to get them to an operative something. So how do they do that?

I mean all politics is a no. We have something called query excellence. So whenever you are writing an associate query, that name this table question may arise. Limit it's SQL queries Okay, so accessing a query which is going to return no record or one or more than one record with a single variable like saying I'm writing a count Okay, it was to try the iPhone Oh yeah. Hey people okay. So this model when these medical records or medical record or measure them in so many records see in your query, you are assigning only to a single record exception with cutting wonder calls, okay.

It will bring multiple records and it will be acceptable. Okay. That means I can simply tell assessing a query That returns no record or more than one record. single subject, current, like account a single object, what's going to return more than one record? Understanding that am I I may get a query system? If I'm not, yes, it may be the emphasis on Korean, anything.

And also easily we have something called a subject. Oh my god. Yes, you can make the image of all directors. Not only it's quite easy Okay, yes problem with some of the records if you work on a subject record and there is some problem that time will go by so don't worry about all these tables and you're contending for your knowledge. Okay. Yeah your database or the database whatever you're writing all are asking for a job for if a no yeah.

So particular job also we may get from asking etc. Okay. No problem problems we are seeing a face populism for a synchronous operation right. Okay. So, we may have to when you are doing a call out to the external application, that time you can get a call out extension Okay, the call out exception, it will arise usually in the voice service or sound shop call out. Okay.

Understanding or not it's a service call out to other application at I everything I didn't know concrete under. So whenever I send in the email, that time we may get an email type of Yeah. So, if you're sending the email that time we'll get this textbook problem with email. Right? So sometimes we'll get the invalid parameter Hello embedded by them. To value system okay.

So you have one method where you're dynamically passing the parameter to that method okay. The same are going to happen if you pass less number of parameters to that method, right yes or no or some deep learning method exploiting a string type of parameter for your passing integer type of parameter. So that we can get embedded parameter values okay invalid parameters applied to methods, right. Yes or no? Sometimes we listen some government limits limitations coming correct. Yeah, so, if any governor limit is coming that time it will be called as a limited person.

Governor right all right. No no no not at all. If we're doing some updating DML operations Then why do you need an email system? Why do you need a call at all? Yeah, you can use okay so it we saw the managers and now we have the American system American the name so we have no ssep have no access to some of their stuff and you can get the objective in Colorado. No as a citizen okay.

You have no Saatchi limitations. They should have all this acceptance rate yeah yes then somebody quirky trip system. Okay. like this so many systems we have so we may have the security person understanding the name. It's always straightforward. Okay.

We may have string a person. Okay. Or the visual force, we may have the visual perceptual isn't right. Yeah. Like as we have definitive navigation given by the end for it. totally okay.

I have a limited time. Politics is all I have Emily, Kirsten, I have email access all these collections on, you can use to handle the exception if anything occurring in your application occurred. Yeah. So what we can do, we can write, try catch, block, and finally block. And we can throw the message also whatever we want to we can do it. Everything is falling under standard for the standard even by Salesforce, but I am so stupid pillow.

I just don't want to use that standard behavior of sanity because on what they're giving, I want to write my own exercise. Okay, so for now, I'm writing my own son, that we'll call as a customer call center. Yep. So how can I write a customer? Okay, so my question is like, my own logic, I need to write correct. Yeah.

So if I'm using the demo system, that will be standard logic, what they're defining that I'm writing correct. Yes. Even when Think systemically what I will do, I will write my own class and that class will design the logic for that message to be displayed. Okay. Okay. So now, the fourth thing is that how can I write my document okay.

So whatever the exception you have okay for the exception you are using everything is defining under the excess under understanding. Yes, we have one new one class called as an exception class, which is the parent of all the exosome illiterate okay. Like whenever you're defining a visual for everything in the apple page or writing everything for what it was, or maybe DML Nicholson or em Alexa, or Fallout Exxon or seafood, Exxon or a thing, or any occasion, they put a curse on anything. You take everything is coming from the one acre sunflowers many acres of honor that dependent type parent is a concern under that different different types of exercises. Correct? Yes.

Okay. So now I need to write like one my coffeemaker if I have a GMO like taxes coming from the parent. Yeah, I'm writing my own a case on my customers. That will compound our own exception. We're gonna define our own okay. Yeah, everything we can do, okay.

Nothing is there any standard offering? Okay? We cannot throw. Okay, we go we need to look at and determine Don't get we cannot go to some other places. Okay yeah I'm talking with the team member we can co founder curtain okay in optics Okay. What we can do only we can add boundaries okay.

Yeah, we can play around it. Okay. So if I want to throw some extra fun what we can do so we are going to define here our customization. Okay when type system like we have a DMX s are not limited to some of the game and a couple other candidates and since I told you later I will write one exception class with a custom Plus I am adding a custom gluster the customization you can catch and thralls whatever you want you can do okay. So, yeah like the emulation coming from missiles coming correct ledger you can define your own method 41 okay yeah always I call exception is the top level class right so I have a class called exception system design class which is a top level class which what they're doing all the excess on what they think the limit exists on or invalid parameter diagnosis on or email exception or color the system particles accept some so you are seeing everything is a child of this class Okay, this a cursor is the parent class top parent class okay.

So, exercise a top level class, which can be a member variable is a method and they can implement an interface. So if I want to implement any exercise on So, I have to write a class which is going to inheritance or implement the exception interface okay with all that it comes up exercise okay. So, what I need to do I for creating a custom ecozone we need to extend exception class okay something like this. So, I am going to define a class publicly I just give the name of the microphone which is going to extense Okay, what is some class okay. So inside this we are going to write some logic He's a system class. I will make it as a customer system.

Okay? Yeah. But tomorrow we'll write how I'm going to write the code for making a customization. My own Yeah. Okay. If this was you clear today?

Yes. Or any any doubt tell me this customization program programmed in how we're going to do how I'll use in a class like here I use some dial one standard exception or usual sir. Like this how I'm going to use my customer custom here. Okay. All these things. I liked it.

Okay. Yeah. Isn't this clear? Yeah. Okay, even just to read it, I'll send it in this material. No.

Okay. Okay. So this and the event out from tomorrow is all about in distress. Okay. Yo Mara have you know I need the water I have one interview I need to buy I want to know like tomorrow I will ask now I need to make simple or else you will be free after one hour I will ping you and I will ask now topic like I mean I got one project example. I will show you that and I want to know if we can do that or I may not as a part of this code.

I'll yeah and that money that attention I received Yeah, today we'll send you some more money. I will let you offer Really? Yeah, that is the reason. Okay. Yep. Okay.

I will message you after one hour. Thank you so much.

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.