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
€46.41
List Price:  €64.98
You save:  €18.57
£39.74
List Price:  £55.64
You save:  £15.89
CA$68.36
List Price:  CA$95.72
You save:  CA$27.35
A$75.43
List Price:  A$105.61
You save:  A$30.18
S$67.50
List Price:  S$94.51
You save:  S$27
HK$390.66
List Price:  HK$546.96
You save:  HK$156.29
CHF 45.28
List Price:  CHF 63.39
You save:  CHF 18.11
NOK kr542.32
List Price:  NOK kr759.29
You save:  NOK kr216.97
DKK kr346.21
List Price:  DKK kr484.72
You save:  DKK kr138.51
NZ$83.04
List Price:  NZ$116.27
You save:  NZ$33.22
د.إ183.60
List Price:  د.إ257.06
You save:  د.إ73.45
৳5,477.48
List Price:  ৳7,668.91
You save:  ৳2,191.43
₹4,173.46
List Price:  ₹5,843.17
You save:  ₹1,669.71
RM236.90
List Price:  RM331.68
You save:  RM94.78
₦61,737.65
List Price:  ₦86,437.65
You save:  ₦24,700
₨13,884.75
List Price:  ₨19,439.77
You save:  ₨5,555.01
฿1,836.53
List Price:  ฿2,571.29
You save:  ฿734.76
₺1,613.79
List Price:  ₺2,259.44
You save:  ₺645.64
B$253.58
List Price:  B$355.04
You save:  B$101.45
R921.65
List Price:  R1,290.39
You save:  R368.73
Лв90.79
List Price:  Лв127.12
You save:  Лв36.32
₩67,757.86
List Price:  ₩94,866.43
You save:  ₩27,108.56
₪187.05
List Price:  ₪261.89
You save:  ₪74.83
₱2,856.96
List Price:  ₱3,999.98
You save:  ₱1,143.01
¥7,687.37
List Price:  ¥10,762.93
You save:  ¥3,075.56
MX$846.40
List Price:  MX$1,185.03
You save:  MX$338.62
QR182.04
List Price:  QR254.87
You save:  QR72.83
P679.94
List Price:  P951.97
You save:  P272.03
KSh6,711.15
List Price:  KSh9,396.15
You save:  KSh2,685
E£2,396.98
List Price:  E£3,355.96
You save:  E£958.98
ብር2,864.89
List Price:  ብር4,011.08
You save:  ብር1,146.18
Kz41,759.31
List Price:  Kz58,466.37
You save:  Kz16,707.06
CLP$47,049.08
List Price:  CLP$65,872.48
You save:  CLP$18,823.40
CN¥353.90
List Price:  CN¥495.49
You save:  CN¥141.59
RD$2,900.17
List Price:  RD$4,060.47
You save:  RD$1,160.30
DA6,724.18
List Price:  DA9,414.39
You save:  DA2,690.21
FJ$112.18
List Price:  FJ$157.07
You save:  FJ$44.88
Q387.94
List Price:  Q543.15
You save:  Q155.20
GY$10,441.17
List Price:  GY$14,618.48
You save:  GY$4,177.30
ISK kr6,976.60
List Price:  ISK kr9,767.80
You save:  ISK kr2,791.20
DH503.40
List Price:  DH704.80
You save:  DH201.40
L884.08
List Price:  L1,237.78
You save:  L353.70
ден2,857.75
List Price:  ден4,001.09
You save:  ден1,143.33
MOP$401.71
List Price:  MOP$562.43
You save:  MOP$160.71
N$923.86
List Price:  N$1,293.49
You save:  N$369.62
C$1,837.28
List Price:  C$2,572.34
You save:  C$735.06
रु6,663.84
List Price:  रु9,329.91
You save:  रु2,666.07
S/186.31
List Price:  S/260.85
You save:  S/74.53
K192.92
List Price:  K270.11
You save:  K77.18
SAR187.49
List Price:  SAR262.50
You save:  SAR75.01
ZK1,346.25
List Price:  ZK1,884.87
You save:  ZK538.61
L230.87
List Price:  L323.24
You save:  L92.36
Kč1,161.41
List Price:  Kč1,626.08
You save:  Kč464.66
Ft18,082.13
List Price:  Ft25,316.43
You save:  Ft7,234.30
SEK kr541.20
List Price:  SEK kr757.73
You save:  SEK kr216.52
ARS$43,928.30
List Price:  ARS$61,503.14
You save:  ARS$17,574.83
Bs345.62
List Price:  Bs483.90
You save:  Bs138.27
COP$194,235.29
List Price:  COP$271,944.94
You save:  COP$77,709.65
₡25,508.30
List Price:  ₡35,713.67
You save:  ₡10,205.36
L1,232.91
List Price:  L1,726.17
You save:  L493.26
₲373,633.39
List Price:  ₲523,116.65
You save:  ₲149,483.25
$U1,909.79
List Price:  $U2,673.86
You save:  $U764.07
zł200.70
List Price:  zł281
You save:  zł80.29
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.