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

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.