Apex and Database, INSERT statement VS DataBase.Insert()

Salesforce Development Using Apex Apex and its Database language
56 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

This conference will now be recorded. Okay, so in the previous system was about collections that are types, okay, so we know, we can collect on using these set or map. And in the same time, we know how to declarative. So whenever I'm writing any optics programming, there is nothing but if my logic or my program, not able to connect to the database, not able to read my object level data or my record, then there is no huge overriding problem. So if I write a program, and I'm not able to interact with database, or I don't know how to manipulate database through the epics programming or through the logic, whatever writing, so I cannot build a complete application. So before I do that, I should know what are the things I can do with database using epics?

Okay, so let me explain that topic. And again, I'm saying if you have any question at any point, stop me and ask me We'll clear all your doubts. Okay. So, now, we will discuss about optics and establish themselves okay and how am I going to communicate to database and how we can manipulate the records Okay. So now, we put that whenever I'm saying object okay. So that is when I say nothing but it consists of so many objects, if you talk about any application, for example, deep talk for recruiting application, we have position we have candidate we have job application.

And if you go to any enterprise applications, you have some kind of objects, okay, right now, if you work in any any project, you will have a lot of tables or objects. Now, how I'm going to talk to that, so, how my object going to represent in a way to epics, so, what is the reference? What is the point there? So, let me show you here something. Let me log into the system. Okay, I'm already logged in.

So see, whenever I'm seeing the object, there are two types of objects. If you remember The custom object and standard object Okay, so in Salesforce, we have two ways here okay let me show that one we say standard object and another one we call it we call us custom object okay. So though objects which we create that we call a custom object and object which already provided by Salesforce we call it as a standard object. So for example, I can say accounting timbered. A standard object or contact is nothing but a standard object. Same way, I can guess nothing more distant objects or wherever the objects which I have created.

And as with underscore underscore see, that has nothing but my custom object. If you see you have created a position object, sometime it could mean the illegal equipment up. Okay. So who isn't? Just we say, as a label but you remember that APA name that is nothing equation underscore underscore c so we'll see if any moment you go on to the object it's a music library object for example okay it's a music application forever I have a music library object. So I have label and a plural label I have a name nothing but I call it as a music library my object okay.

So, it may be any object but you see the all objects whatever I have everything in Swift underscore underscore C. So if you see any object ends with underscore underscore t nothing but the custom object we have created, okay. So the way whenever declare a variable, okay, nothing but it's a integer or string, we define integer, then my variable name. So, this variable name if they say, integer roll number. For example, I can say roll number is a variable, which can store integer type of data. Okay, so mind that can be integer can be a string and my data can be computed record nothing but if you see here, if I have an object completely I have a database completely and in that database, I have a specific object created. Let's see, this is my company database and insert method is I have one object considered this one object, okay.

So, when I say this object, let me make it normal color. When I said one object for me, nothing but in this object, I will have many records, okay, they may contain candidate information, maybe it may contain my music, informations main content, my library information or anything. This is nothing but my records in one object. It may be one record to record any record any number of records. So how I can represent each record. So if I say let's go to the recruitment application, I hope everybody knows that when you start learning the Salesforce, okay, so now Let's consider this object name nothing but a position object which named in ultimate position underscore underscore C. So now, this complete object what I have okay I call this as position object okay.

So, how I can represent one record so, my person object may contain many records nothing but if they go to excel sheet Let me open Excel sheet here if I say this is one object for me or table for me okay if it is one table for me okay. So, these are nothing but one one record one information concretely, if this is a table of employee, then this is nothing but one row nothing but information about one employee okay. So, how I can represent it. So, these we will consider this into one row, this row is one instance of this object this contains All the columns, but introducing timekeeping. So when we say one record or one row, we call it as one instance of that object. And when we say instance, nothing but there is some memory allocated to it, okay?

So whenever we say the object, and if you see when you create the instance of that object, nothing but we create one row exactly, but this is one row. So how do we represent that? how you create a new row, how we get that row? That kind of thing we'll learn today okay. So, now, hash thing what is object and how many objects are being printed? So it may be a standard object, maybe a custom object, all the objects have a PA name, okay.

And all custom objects and sweet underscore underscore C, which will use in the official epics classes that and the moment I say is instance nothing but a plan. Target account if one object for me Okay, in account we have many records, if I want to have one record exactly on my system also on my program, I think what I can say it is one instance of the account nothing but new account. If you see this account, whenever you see a new account or new on a class name, it is exactly one instance of that object when you write like this, so, that means we just create one instance. Okay, so just one row equals empty row, okay. And in that empty row we have to fill all the columns we'll see how we can fill these things. So remember, you it may be a standard object may be a custom object, all the objects can be represented as a subject.

A subject is the superclass. Of all objects. This a subject can contain my standard object can contain my custom object okay. So, if you want to present account record simply you can write account so, all of did nothing but in one class for me the thing any object you name there is nothing but one type of class inside my program okay. So, for inertia account object nothing but account is one class same way when you say position object nothing but position underscore C double underscore c is nothing but one class pony. So, all these can be reprinted also add a subject.

So, a subject is a superclass or base class of all objects in Salesforce Okay. So now, whenever we want to manipulate with the object, either you can use a subject either you can use that object ID it may be account or police or police or anything any concrete until now No. Okay. So that way we will be building a subject. So now, we understood Okay, so I've written out the embodied superclass of my all objects, you can assess the object with a subject or with a specific object type. poignancy a subject, it can hold any type of objects.

So in a common object, I have a specific fields in position object, I have some specific fields, how I can access that fields. For example, let me go to here. I will open the developer console. So as we know we have already account object. I'll try to manipulate something in account. I will try to create one record all I want to instantiate something.

So I went to our universe window. Let me open this Let me delete all the log files, we have many logs here. Okay. Sometimes you will see like, as you asked one day, so why May this be a concern not being loaded? If you see there are many log files out there. So it meant that a lot of times are occurring debug level metric correct yes, I just want to get into it don't need this piece of code.

So, how I can refer objective man in Maine epic programming. So, how this is a similar way how you create any variable, it may be a collection type, or it may be a normal type. Okay, so, how declaring declare variables here boy, I can declare one account variable account sec says When I have written in previous years on INTJ number one, so when I say this one, it is going to store what it is going to store one value, type integer. So when you declare an integer number one, by default compiler associates a memory, but I'm going to create an account sec. Okay for this, that means I'm going to create a reference or create a variable of type account. Same way, I'm going to create a variable number one of type integer.

Same, I'm going to create a variable sec of type icon. So this is nothing but what can store this sec can store exactly one account record, because I have specified which type account number one can store exactly an integer value. So my sec can store exactly one account record account type of information, okay, but to store that we have to allocate some memory for that region. I have to see if it works. So you may ask why we didn't specify a memory for number one. So far the predefined types, like our integer string, automatically compiler associates, or maybe like seeing the runtime, my epics runtime engine, allocate some memory.

So we don't need but for account or in a socket, we have to allocate memory. Even for the collection type, we allocate the memory, if you remember, going to declare a list, we do like that list of integer or at least equal to new list of integer. So same way, we just allocate the memory by calling the constructor. Okay. So now, this is a donut, I'll just remove this. So I did account is equal to one that means for the moment you right this account is equal new account.

It is nothing but it is just creating a row on this object. If I say account object, you just create one more. So in this row, I have so many fields. So who is real short, have some hello how I can assess it. Sam are you what you can do? So let's consider in this account I want to assess name freely, okay.

So I can set SSA dot name. So this these are nothing but Mike field what we have in the account object if you go here, if you go account if you want to assess any fields go to account field so you have a PA name for everything. Whenever you do programming, everything we need API name. See here account name is level but if you say account owner each level, but if you want to assess in program you have to use this field name. The fields which are already given by Salesforce is not ending with underscore underscore see what if any custom fields all ended with the underscore underscore see. Okay.

So now if I want to use account name, I want to create some local account name so I can access this name field. So simply what I can do, I can go to this tech console sec dotnet. That means, if you see, I have created one specific record. In that record what I'm going to do, I have one empty reference here, empty row, and I have a field called name. And in this name field, I want to say hello, then for this sec, nothing about this law, go to the name column and set some Hello, or go to the some clarity column said, Hello. So where do you want to set which value you want to set that you can do here?

Let's say I want to set a cc name equal to something like C test account. For training running something, am I good? Okay, so, like that portable filly one, we can assess it. Okay, so if it is a custom object, let's see I have a custom object on my on mail. I'm just opening that. Consider this music library.

Do an object for me custom object, I want to access that object what I can do, I can go to a music library ami, let's give it a first name or the ML new music library. And what Phil I want to access I can do that reference name dot field name. So let's see, consider I just want to take a special feel. Let's is public is a Boolean check box check was nothing but boolean value. So I can say it's probably true or false. Okay, so like these, I can assess my object in program.

As I said, Our pecs is completely data driven programming language and which is highly integrated all about system. That means See, I have my database. I have my programming to assess the object. I don't need to write any other logic just simply record the object name here. Automatically my artist can talk to database. I don't need to have a connection open connection close assessor database server name, nothing it everything integrated.

Okay. Select these three axes using objects. So now, same way whenever you see I associate this using account, okay, using my custom object. And also this can be represented as a subject see if I want to eat I eat as object. Let's see I give the name as is OBJ equal to eat can contain my account also because I said a subject nothing but it's a super type of all objects. It's a parent of all objects, any object can be contained by a subject.

Same Same way, I can also store a subject equal to new position. So when do we need to write this as objects? For example, position a customer object C. dynamically when we assess some object, we don't know what kind of object I'm going to assess it. Okay, I just had okay I have an account object and I want to get all the I object associated that for this or VPC, whenever you open an account record, under the account, I have contacts, I am opportunities under the opportunities. I have operation line items or products, okay, or gases under the account. So many of your so yeah but so now if you see here, maybe contact a person case like that I may have another custom related list I don't know for the objects I have, I'll just hide it and don't query for the account.

What are the related object I have? I want to get it so I don't want to write okay get give me contact apportion these all the objects I can take us to a subject Okay, once they got a selected then I can manipulate what is the subject name or APA name by using dynamic address for that purpose. We use a subliminal money. So I'm not going to that level when I'll teach you the dynamic effects there that time I'll give more example of a subject But for now, you can just remember the objects you can represent as its own type like account or music library or poison or it can be contained by the subjects okay. So, this is one one thing. So, now, if I object how to access a field, you can access the field by using the that object reference name with dot operator and my children.

So, any object field when you want to assess simply you dot unfilled and financing fill them, it is all about a pain in in all about the development, we talk about APA namely nothing level nothing is everything will be APA men. Okay. In this way, we can get a solid records. So now I cleared the account. Okay. So now if you have a database what we can do, let's consider Let me close all this windows.

It's confusing a lot. Just give me a minute. And close everything here. Below you have any questions? No. Okay.

I'm just putting everything so that we can just go as easy. So now let me clear this. So now we create one account object. So nothing but I have one specific object. And in this object, whenever you have a database object, what is what you can do? So it's an empty empty object for me, I have nothing.

So now if I give you a table, just think you have Excel sitting in this Excel sheet what you can do. First thing you can let me I'm just putting some random column name here. Okay? So not to confuse you If I just mention here employee name, okay. Then I mentioned your employee name, employee number, then email like these are few columns, okay. So now, if this is a table for you database table for you what you can do on this.

So what kind of operation you can do any idea? insert or update, delete, okay. So we talk technically INSERT, UPDATE delete. So it takes in layman language, I can create a normal record I can create a employee record here. So I can give the name as asuni and I can filter in some sense. Same way, I can give the name as three LLC employee number is something an email is three R x ray t.com Okay, same way I can create one more employee as is correct and I can go do some number and some email address Okay.

So now what that means first thing we saw an email whenever every database object, I have created one record nothing but I am doing the insert. Okay, so if your database object past activity, you can do the insert of the records. So second what we can do, if I insert the record, then what more activity can do okay, I just want to send the email that discusses that also I should do it. I should be able to do it. I can mention the email address URL as is. Let's see X ray u.com for example.

So that means I'm updating the record which I have. Okay, so then I say okay is this optional record is completely empty it Don't want this record simply I can edit it. So, that means from database I should be able to delete the record. So, again for example, I have another assist maybe duplicate record with different employee number okay and some email so, I tell this both at the same record, so I should be able to march it also correct. So, this kind of activity we do. So, after all these things, I just want to see the like this I may have the many records many employees, I want to see the record by employee, okay, let's see, I have one more column which I call us salary, okay.

For example, so in this place what in what I do, I want to see the employee whose salary more than Sanchez became up, I want to get the record from the table I want to access the record I want to view the records. That means I can use some records for it. So whenever you talk this there was activity It is divided in two parts in the database language you see the complete activity, they were dividing into two parts, okay? We may perform some DML operations, but we may query the records, okay? Nothing but query means nothing but I am going to get the record from debtors. Okay?

Or I'm going to manipulate the record in the database. Okay. So manipulate nothing but I'm changing the records there, get means I'm accessing the information, I'm not changing anything, okay. So, my app is program should be unable to perform this DML and query. So what kind of DML support enables and what kind of query you can do in epics? Okay.

So past we will see the DML operations, then we'll come to see the query operations. Okay. When I say DML operations, what is that? As we mentioned here, insert, update, delete. Nothing worked. So simply all database operations I am writing in this short form.

See Rudy, if you remember whenever you were creating one field or let me go to that place in Salesforce. I'll give you a little bit idea here. As I just go here, set up I'm just going to see profile Let me open this profile page. I'm just going to any any stupid little I'm going to this contact manager profile. Any profile you can go I'm just going down to some object See, II see this object, what kind of object level administration what you can do. I can read the record from object I can create a new record.

I can edit the record, I can delete it. Now think about all these things specifiers crud operation, see nothing but for create read, update, delete. So, when whatever language you use the these four operations are the basic operations you should be able to do in database, you should be able to create a new record in divers, you should be able to update the record database existing records, you should be able to delete the record from system and you should be able to read one particular record or many records from the system from the database from the object. Okay, so how this is going to happen. So this all operations divided in two parts, the similar query going nothing but I'm saying get the record or read the record. So there are many mechanisms to read the record we will see each one by one and semi DML a team but we said create which is nothing but text Legally insert and update, delete.

These are the three basic operations plus we'll see this then you will see more and all the different activities. So now the example we're doing, I want to create an account record. So now the moment you create an account by user interface, we go to Account tab, we'll click the New button, the moment you click New nothing but we create one empty instance of the account object. So please, I have so new here, the moment we create an account update. So with that, I am just adding one empty instance. The moment you click New, it is empty instance for me.

Okay, so now with this I need to fill the informations let's see I give the test account. So the field value I want to fulfill then I click on the Save all activity do does this save nothing but inserting One account two main account object. He does thing what I'm doing on this user interface, how I can do it programmatically. If you see here, if this is one account object for me, okay to assess that in programming what I did, I create one empty instance, I'm just going to do everything. I'm going to create an account record programmatically I will see what happens here. I did account let's see sec, which I said new account.

So, the moment I did this one, it is nothing but create one in particular. Now, I have to save it. The moment you want to say like in user interface, you have to feel the field village which one you want, you may feel all the fields or you may feel the required fields, whatever the program declares, based on requirement you need. So right now to understand the logic, I just want to feel the account name. As I said, I can assert this ACC dot name. The field name of the account object can be accessed by dot operator Then what value are you under set?

Okay, let's I just gave name as test account 123 then I go here, I did insert FSA. So don't create nothing but it's an insert insert statement for me right. So, there are two type of that I was language given by itself was to manipulate one by DML commands and one by DML functions or DML methods to thing. So, this DML activity provided by Salesforce in two ways. One we call us, let me right here is going to go down okay. So, what is that one we call us in DML command and one is nothing but bml methods So, they will have a word I can say that I was methods.

So when I say DML command, if you want to insert a record, I can re insert, and these insert command can store or can insert a single record, single, a subject record or any any object record, or it can take a collection of record. Okay, so you can create a list of account at a time, or you can create a single record. So, right now, I'm showing you a single record then I'll show you what is the same method in this class I have for the same operations. Now, I feel the same way I wrote here. This is named the moment I click the Savior. I just gave him this name as you I account by the grid anyway.

So just to make a difference to understand to depend upon I'm just kidding like that. I click on Save momentarily Click on Save you'll see there is a account created with name as you know, whenever the account created, you see every record in Salesforce represent with a specific ID. Okay, this ID as you can see right now it's a putting greater it is a 15 and 18 characters ID the difference. So case sensitive case insensitive, which I'll talk in the arm instance. Okay. So that is the difference, I will tell you also in the interview questions.

So we carry those two account record here. So the same thing I want to do in the programmatically, I create the instance, I set the field values, I just set one field right now, I can set many fields, then I hire, insert operation, and I click Execute romantically execute, you see, now one record will be created. Let me go here. I just refresh the page. We'll see when our concurrency test account 123 right now when the neighbor to step on 123 here In database one account created. So now it is about one account if I want to create 10 accounts, that means I am going to create collection of accounts.

So I have to replace two options if you aren't creating accounts what I do normally as a bad practice as a bad programmer, what I can do, I can fit all the 10 accounts at account one account two accounts, I can do 10 time database operations instead of that what we should do always always to write one optimized program to write program which will be boost the performance of the system we should heat database as much as low as possible. Okay, so as less as possible, you should be database. So if something you want to get out of is instead of going out hitting the database again and again, go on a database, bring everything nothing but like if you see if you you want to Get something from kitchen. Let's say you want to get the food from kitchen, you go bring the chop it or rise one time, then again, go bring the data one time, you can go bring the subject one time.

So you were going multiple times to one place, assessing some information and coming back, it takes time to go to the same test students. But if you go on time, put everything in a plate and come back. So you save some time you save your resource. Similarly, if something you have in database, and he won't notice it, don't go again and again to bring go at a time higher all the operations completed and come back. Same way. So if I have 10 accounts to create, I should not hate that I was my 10 time use insert means I'm going to hit my database.

Again one instruments going to hate that I was you should not hate that a second and again what we should do, we should keep everything in the collection and save it. So if you see this is one account, I like this I have 10 accounts. Same way if I can say I have 10 integers, so what we do, we create lists of integers I interlaced equal to new list of integers where I can store any number of integers correct in 2023 to like this, the schema comma Okay, so say my EPC list of integer can contains many integer values. So list of our content content many containers. So, what I can do here I'm just going to create a list of account types. This is a list equal to new list of this is the same way how I can create the entire collection.

Same way I'm creating the account connection and in this accumulation, I am going to store many accounts. Okay, this is my one question. So nothing but whenever you want to store something in the list what we do, I use this add method essentially store our add method, this is one but I want like these 10 accounts. So I want this piece of logic can be cleared for 10 times can be good for 10 times. So this is a simple program for writing for loop to understand make you understand my object, your mind operates on insert operations can contain collection of elements and talk to the database. So, I'm just doing here for integer i equals zero, i less than 10 i plus plus anybody confused on the for loop.

If you want to accumulate follow, I'll talk about that also. any external signal to follow everybody's heard about this follow a series History. And Okay, perfect. So this is nothing but I am repeating this statement followed for 10 times how many times this ignition switch start. In here I'll talk about this follow in one system. Maybe in the next one I'll talk about this loop do while while everything.

For now just understand, these are the C statements which are going to record many times, I'm just looking these statements how many times you look that is defined here in the time condition satisfied. So I create one account already in the collection. In the end, I just insert the account list. So now you see insert SSL is yes, this list contains many accounts, collection of accounts, and go to database and stored in database and come back. So I go here database one time. So here are what I mean to here.

Let's see. Insert 123 to say segregated I'm just writing testosterone plus i Either a military second Judo test on one test one two like that, I just had to get it let's see, am I able to attend a concert not even a go to a counter is 19876543 200 everything written. So whenever you write insert insert statement, it can store it can contain exactly one single record or it can contain a collection of records that just I want to say here till the point all clear. Yes, or sunny? Yeah, perfect. Okay, so, this way we write DML statements, these are nothing but DML statement we took insert, update or anything DML statements.

So far this insert, participant database class methods. What other approach we have, we can use using How we write the insert statement, it can contain a single record or multiple record Same way, we can write some predefined method given by Salesforce which we call as database classes. So database methods that will write however right insert for same insert, what we can do here, we have a method in a predefined class who should call that disclose for database class in database class, there is a method which we call insert method method means it will have some parameters. Something is like this database for inserting backward inserted record what parameters we can pass, I can pass a single record or a colossal record. Okay, so let's see I wrote a sicilies and there is a boolean value false or true, okay. So what to what is this also true?

So now, I will tell you one example. So this is really so okay. Let me go to here. So the moment I insert 10 accounts, so let's consider I have some validation rules. Some validation rule validation rule I have defined in the system. So out of 10 account, let's see account one like this.

I have all the 10 accounts right here for me. Okay, so I have account one, account to account three, like this, I have accountant. Okay, so now when I'm going to insert all accounts at a single time to mentor tables, so it may happen my validation tool, there is some validation rule, which may fail. So my account let's see past account when I'm going to insert it method. So all the records we're going to insert, everything would be rolled back, nothing is going to insert probably jumble yesterday. Can we have a chance to see the database class?

I mean, to understand what that is, I'm doing that I'm doing that. Okay. Okay. Then I'll show the programmatic and you can see he pay the interest faces name and I just try to liquidate. So, what happened here, let's close this one extra character here I just click Execute see is throwing the exception third. So, that means I was trying in my collection I have generators, so there is not a single record inserted in database okay.

So, what happened here, so, all the records rolled back from the transaction, so nothing got saved in service. So like that, if I have hundred records and or my 99 record like this is hundred acres, so there is no validation fail till my 99 number of acres, but on the hundreds of acres on this acre when trying to save in the rivers, there is some exception occurs there is some condition of it. So now on this part, what will happen, all these records is going to be told that nothing is going to saved but I may want Okay, I will just save the records, which is good to go. And I'll just roll back To record which is not valid, or which is not able to save or which generate the exception, I just want to roll back that piece of record. So if you database insert statement, like you usually insert a serious fish, it will not take care, you don't roll back everything.

So database method, we have something called database insert, give the collection name and give the vulnerable true or false. So this second parameter True or false? Depends, do you want to roll back all records or not? If there is an exception, or do you want only the success record should be good readers. Okay. So if you were to roll back the record, then specify true all records.

If you want to know it will allow partial saving, then go once. Okay, then let's see. I will do the same activity with database insert method. Okay, let's see. I just want to get the record from 2020 To 30,000 Records I want to create. So how do we insert this list instead of this statement, I'm just writing that is dot.

See, I have insert insert can think entity can take parameters as a list of one collection of records, or it can take the ML off cents, okay? It can take all or nothing but I mean just all these parameters, we can set it here. Okay, any day insert, just focus on insert lines. So I just want to go these all or nothing. Okay, so what is my collection? Michael is nothing but I said, it's the silliest.

This is my collection. So I want to keep our silly zip codes I want. Okay, so now, I want to set name for all records, except let me go here that you see before I don't At the named age not not faring. So for the 29th record, I don't want to set the name. That means all the records have the account name, but one record, I don't have the account name, okay, I just received a, if this is the continent record 20, I start from 20, it will go till 30 on the continent record, I don't want to share the continent. For all other records, I'll set it these sub lessons I write with insert.

So what happened the moment I tried to execute is Eckerson There is not a single record created in my system. Let me see that there is not a single record created in my system till the test upon nine. So now, the same thing I am going to do with database insert. So this insert statements on mythic system, it's thrown an exception, but since database insert when I do I just click into good versus whatever, Oh, I missed a semicolon. Just give this video now click Execute. So now see I didn't get any exception Something happened in my system.

Let me see. Let me refresh the page See, I just create a county to lead, but it is just a roll back that record which have the concern. So I found out passel, it occurred in May and I was so when I say that I will not insert it is just a method. So, do this method have some return type or not, so, it is not generating system. So, how I will know which record got fail or not okay. So, whenever you do database insert, there is one specific return type we get we get the result okay what type of return result region it will return me that is dot sub result okay.

So, the records which you are going to insert or which are going to manipulate, so, for each record, we get it done it successfully insert or not and that is nothing but we One save ledger data that I will start saving your data. So let's I'll just give the name as my insert list equal these are insert result. And then you can see the variable name equal this. So that means when I do insert, what is original came all record inserted or not even a record fail, everything will be stored here, because it's not going to throw me exception, but it will give me the result. These are the results have been on this DML operation. Okay, the moment you do insert a return miss a result.

Okay, how will manage this? Okay, I want to see out of all this occurs, which record got failed. Again, I'm just changing this, to understand this, that I'm just going for 30 to 40. And I just want to sell the record 35 because in the between AFL CIO, it is going to fail completely after 35 or just 35. It's going to roll back. We'll see.

So how we'll see this one so I got one array of records. The Return of the in operations and we can see from here for again I wrote The for loop okay I have originally in the insert ritual variable or thing but in this I just go to iterate on each record let's see, I just see my recorded message and so, now, I can see for each record majorly successful Not that I can check with a condition if my result is success or not is a method predefined method everything you meant by this was first Okay, success or not, if it is not success, I will show the message or the rate will say success means I don't do anything. If it is not success, also what is error ie the ritual is not success. Then we will see what is the method I have? Sorry, what is the record and why it is failed?

Let's answer speed between the debug lightning Good, I didn't teach you a custom handling mechanism. So I'm not doing try catch or anything any, any any clicks on I'm not doing, I'm just doing what is my error here, the moment it's not success that means you thrown me the error and all the errors I will get from get error methods. So let's see, I want to print all the errors for database dot errors, let's hear. So call this success ritual, whatever I have, I just want to print all the arrows whatever I have. Okay, so, this kind of operation does have to follow by writing here. What is this class we'll use in the all insert, update and delete everywhere, okay, but here I have several jobs in there Plus, I will have different kinds of class.

Okay, so now I'm just printing this little message. Okay, so the error dot let's, I'll just print the error message here. Docker images. This was I did only Okay, now I'm going to do we'll see what happened. I left on this program completely. Okay, that was I missed the year here.

I'm really bad in this index being at A, B, C. Okay, something happened. I don't know what I mean. We'll see. We'll see the log file here. If anything ever comes, we'll see what is the error? Why is this error error calm, which doesn't throw the error something error message record field missing.

So for one record, we got this error in multiple records and you can get this one. So now, what I'm trying to say here, let me show you the Complete database. class and what are the methods we have Okay. Then we will discuss if any confusion here will will close all your company will be confused. Obviously, I know that I am not saying to remember all the classes, all the mentors, always you assess this, you have more or less you can see if you go to these, your database database Glasgow quickly I'll show you all the methods on how we can use that. This is opening Just give me a second.

See, so, there are many methods like convert lead and we're going to talk about all these things now. So I just focus on something we call insert. See, I have one method, which I call insert insert To record to insert all or none everything even go this method. So, there are many methods you don't need to remember everything. So, it is going to return me one database service for each insert, I will go and get the return of database stored separately if you're going to maintain collection of records then you will get database dot Sara data and this database are several of the class for you you will get which records are being saved or which records are being failed all the internet presence and their associated activities okay. So, now see the program what I have written here I mention everything on this till this part you everyone clear?

Now we came something this back. So now I said whenever to insert it is going to return me the result as an array. So the operations of the collection what I did, the operations is success or failure. Okay, everything will move toward here. And if you want to manipulate there, then you loop on that operations and so on that result, and you can so you can handle that. When you learn the excellent handling then you can see how nicely we have to handle these errors just now I just painted.

Okay, any confusion? One question? Yes, please. So we got only one that was right. Yes, because why one because I just keep for one record not to print this. So let's see.

I'll just go a little bit more here. Okay. I gonna have delete all these records. Okay. So let's see, I just want 14 Hi. All right.

So all i not equal to Okay, not equal to delta significant difference. So what what is the court? I don't want it only say once. Okay, I got it. Got it. Perfect.

I don't want it. Okay. I think cynical confusion so we use save reserve just to manipulate the error that is what was the reason for the failure of the records? That's it right? Correct. Correct.

That's acknowledge only to see what is error or if you want to handle that error then you can write some accidentally managing like you can throw it or you can notify to someone Okay, this has happened because if you don't do this, then you don't know all the rest all the records successfully inserted or not. For example, I will say in real time, we have a batch operation okay. So in I will talk about the batch of incoming classes. So in this job what I do, I am just taking one piece of records to inserting or to update and out of 1000 I just see 10 Records getting filled to hold that 10 Records. I don't want all my job to fail. I will allow my 990 record to persist for lead that tender go to hell, if Phil how I know.

So I can write songs. piece of program here which will send email to me okay this technical got failed you can go and fix it manually or you do something. So, how I will not know okay if a percentage or that file and I will get notify from this method okay these are the records tale from this operations because of this error now you go and manipulated manually or fix the issues so that we can take care in the network next job. Got the point how we use in the real time these these scenarios? Okay. Okay.

Assuming all clear. Yeah. Perfect. Okay, so, how do we insert so in the next lesson we'll talk about update. Okay, pass through class name. I didn't talk so much about this operation glitch.

Just us coming to programming. I don't want to make everything bounce. So we'll go slowly. Okay, just reload the insert. For next lesson. We'll learn about, update, and delete, match.

So, SSL that Nathan will close all these tabs okay. If i is not equal to 45 I put 50 vices to error will come right yeah see okay I like you could also you good days I will show in the log file the loading lock file will just give you a second to the system let me show the debug log here it is wonderful because which is the right come here complicated message if not success is not equal 45 in order to be defeated this will come to 35 So, how am I gonna introduce you in the account level? Let me rephrase this if 55 not entered and 4545 Okay, start from Up to 60 so ignored came Okay, I'll just move on start from 60 to 70 and I just keep 61 and 65 that I'm in main loop I was not in particular so it's one one message and now I just did for 61 to 6061 65 to skip Okay, so now you see what happened if you go and see this it will appear Okay, so now we can get the record ID the number know where you got the message everything you can manipulate and we can send the notification to someone or we can be like sensitive we can compose an email from there and we can send it I will teach you everything how to compose email, how to send the Excel set everything okay.

So I hope today class is not confusing. So very simple thing I will say. object can be any subject can be the object Okay, instantiate the object is a new keyword assess the trillion dot operator and for to perform DML operations like insert, use insert statement or insert database class method, when you database class method, it can be passively or it can be rolled back all or do all or nothing that nothing but a second parameter and my insert statement can take a single record or can take a collection of records and when you do with that, I will record it return a result array from this array we can take a successful failure and if you want to put some logic we can write insert that we discussed only this much any confusion? No, perfect. Okay then we'll meet the in the next lesson. We will close all the methods like the other mentioned here will close all the subjects.

So, so well. We'll talk in that I was DML like INSERT, UPDATE delete module. So cool SSL, and how you can look at circles and say subject collections is nothing close in the next. Okay? So go through all this things and the Google quatre database methods we have in the artist class. Okay, I will also share the link with all of you go and check once.

Then the next session we will discuss all the other topics. Yeah. Okay. Yeah. Perfect. Okay, thank you.

We'll meet in the system. If any questions. Thank you. Thank you. Thank you.

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.