Relationship query and Trigger example

Salesforce Development Using Apex Get Started with Apex Triggers
1 hour 13 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. So, till the time we have discussed about what is trigger and trigger contest variable and we have seen a small example. Okay. So now we'll do another example. Okay. We will see another example how to use the master detail query, okay, like the five minute trial record, how can I call it the master record or repayment Thurmond master or how can I get a sale?

So, to explain that as Let me explain the concept behind that, what is master control query? So if you remember when I say so PL, okay, nothing but we just hired a query where we got the least of the curse, or one a subject, correct or maybe least have a subject or maybe integer, nothing but my aggregate query result. Okay. So now, when it came to these plays, I'm just going on one object. So in sometimes we have This room, if I have two objects, and between two objects, let me clear it. Okay, so if I have two objects, and between two of your relationship, so let's see this is the object and this is our object.

And we have defined between these two objects, we have a relationship, what kind of relationship? Okay, let's see, between these two objects, we have a one to many relationship. Okay. So let's see this is many, this is one that means this is my master record and that is my child record. Okay. So now, if you see between these two objects, and if the if you observe this diagram, you see between these two objects, there is something defined relationship.

We said, okay, between these two objects, I have a relationship. So I'm just talking this line, what you see is the relationship. So for every relationship, we use to give you an For example, if you see, let me go to a any object, okay? I'm doing the division sunim I just go to Object here. Let's consider the object called Java application. So now from Java application, I have innocency using look over my shoulder to candidate or position if they go to this candidate, this field Okay, so candidate is a master and job application is my child.

So see we haven't listened to namely dependence. So there's nothing about this relationship name what we define, if you visualize it is this essential, okay. So just to know what we have, we should recall the relationship now. I only listen to them. Okay. So now when you navigate from this record, child record a parent record, you can use relationship Name field to credit.

So for example, if you see Have a common content Let me explain yours. So, if you see a Kong okay and content so, one account may have many contents. So, for example if we go here let me open a two three account now, if you open an account Let me open up one which has some contacts if I go to these, so, this is one contract under which account under us unit oil and gas person, we have one contact, okay. So, if you go to go to these account, you can see under this account, I have four contacts. Okay, so, that means I'm trying to say so I can have many title records and one master trigger. So now whenever I want to relate Mind master record objects field in McCoy.

So in this example, if I am calling on the I'm writing a show quail in contact and I want to refer few of the account fields. So, if you see this from contract to account, what kind of relationship we have the recency of the account, so many to one, so many contracts can be tacked to one account, if you see here in this example, I have many contracts that to one account, okay, United oil and gas Corporation. Okay. So see that that so many contract officer to an account. So let's see, if I want to fetch the content, what do I need to do? I need to do select the let me write it directly here.

Not in Notepad. Let's go into Developer Console. So I just went to this file. Let's open. I want to open the objects of each other they want to. I'm just going on the contact.

I can just try to filter from here. The content. So here you can see all things. So this is me checking ID, last name, first name. Let's see. This is last name popularity again.

Okay, last name, first name. Now see, I have this one. Let's see. I want to Coney this contract. Oh, yeah, my account is this one. I have just received my god.

I'm just calling all the contact first name, last name for this account. He called this one. So this is normal. So feel free to use us. It will give me collection of contacts. It met all the time.

Context. So with this, I want to get my account deleted. So now if you see if you query this contract, so with that I want to show you on each level each contact level, I also associated associated account number, and number of employees, or maybe account navel display, and account number and display unwelded. We know these three fields I want to display. So what I can do here, simply on this query, whenever I'm going to query on a child object, and from this title of the query, if I want to get the field from the parent object, I'm putting a child but I want to get the field few fields from the parent object. So I'm just navigating on this way.

So from child to parent, boy new go, you can use my relationship name to get it. So now let's see within our common contact, what kind of relationship I have The pay go to this contact they go into here the human contact, let me see what are the fields you have? Let me go to the View object. Let's see, let me go to the contact. So I just taken the fields here. Now see I have a field called account account name nothing but lukaku account.

Okay, so my lesson is child name child relationship name is contact. That means whenever you come from if you're calling on the account object, and you want to give some record on child so when you're coming to the child in see the armor in which direction and coming from Master evil coming to child, that cane will use child is a sensitive name. Okay, so now we're calling home the child and navigating to parent. That time we will lose mastery lessons you've learned nothing but I can say Always messages in him nothing but the field what I have here, if you see between contact an account, my field name is a conquered. So I will refer on these. Let's see what is happening is external fields.

So now, first name, then let's see ISIS with account dot. Okay, name does this one's ID, I think the let's see what happened my account name here. Let's see, I want to specify account dot let's see this relay wanted the field will take our revenue is right here I just hit the API name of that number. Okay, so now what I'm trying to say here, whenever you're calling on the sale of Jade, and you want to get anything from the parent fields, simply use my previous Lessons if name nothing, but in that case it is going to be my field name, if you see on this contact field this Finland and it is a standard field was given by Salesforce If not, then what we have to do, we have to use with underscore underscore. I also that seems also okay. Now let's see.

Now see why we understood Okay, if I wonder if we get from child to parent, I simply use my relationship name, dot field name What a word for standard object there is no relationship name, sorry to interrupt, relationship name or field name. Now, if I can set a master indecision, so the C field name I just made such as account card. Okay, let me let me show you the custom object, then you'll be you'll have little bit more clarity. I'm just going to show that. Okay. Let's see.

I'm just going to this object. I mean the Java Application Object now okay. So now from Java application, let's I'm just going to curry fulfills that ID name. Let's cover letter cutters. Okay, this many things I just created. And what is my field name?

Let's I want to get my candidate intermissions. My current candidate name is candidate underscore seeker. So let's see I just pulled this I got this many interesting Okay, Mike is good, but Wayne, I want to assess my candidate later please. That means if I go here to any job application Okay, from Java application, you probably want to see this candidate information. So I have navigate to here. So see this is nothing but this is used with a relationship field.

By default title underscore underscore is equal field relationship. Okay. So I am the licensee and field delivery c Cpc now one displays okay I got my candidate two candidates I feel them but the relationship name will be candidate underscore underscore Alisha custom we specify underscore one as well but if it's a standard Intuit treat the same way as the field now what is it innocentive name imaging here candidate underscore r let's see password okay might be a good you can see that you know something right. So this is nothing but mind field relationship. And if your custom object then it's going to be understood understood that he started object then it is going to be my default field Okay. So now this is this is one part so now all with this example we understood Okay, we're navigating from child to masters now let's see I want to correct And with that, I want to get some information about in the code.

What to do there. Same thing we'll do now, let's again I'm going to this my account object. Okay? You can hear the nurse ID name and type this refilling coding. Let's is coding my top 10 not uptrend let's see this one first we can doing now account for a record many, many accounts so I don't want to make any confusion. I'm just going to curry this to speak account.

Okay, I equal this romantic qualities. I'm just going to get exactly one account and with this account, what are the contacts associated? It may be one, it may be many, how many contacts associated, or you want to hire and get it okay. So now what we'll do here, so now, there is two options. So simply, sometimes you if you remember we can do this way, let me write a small piece of code. I'll explain what it is.

Now let's see, I have my, I don't have any account ID, okay? I want to query all the accounts and the official contacts. So what I can do here, I have written for, okay, account, sec, let me make it maximum. for sec, I just note, select ID from account. And what are the ID columns. I'm just keeping everything in a set set of ID, all sec ID equal to a new set of ID.

Now here on this set, I am going to walk All account IDs what I have that are what I want a cc.id. Now, again, I can tell you one more query, okay. For contact corn silage ID, okay. Let's see just covering these fields. When you go into contact, we just carry all this information. So these inputs and I'm just taking black name first name from contact your account ID equal to discharge is a collection not amortization equals in when your collection of elements you're in, okay, so I got God the content so let's see I'm just keeping all contents in a list or maybe a map.

Let's see I'll insert a map. I want to keep connected like account ID and the associated contents. Okay. So here partner account ID. So let's see here map of string list of contacts Can I declare like this new member, perfect string, then list open back soon any confusion till now you can put the list as well with the map map and then the Hello can be anything it can be another collection or can be a specific title. So this American content anything okay, so it's not a word.

Mikey's going to be a string and maybe Hello is good. into a collection element okay. So whenever it map is going to be interesting that's going to be map okay what is my key type and what is my name Hello type okay then give the map name equal to new mapper okay what is my type of the key and what is my type of Hello type means there it is okay. So as we understood before when I was doing it, it can be a primitive type nothing but like integer or string in that category a Boolean or it can be a subject okay. There are effects okay or it can be a collection a point is a collection nothing but it can be a list it can be a set it can be a map okay. And that means, this tape can be a map also can be used also.

And whenever writing lists. It will like this list So in our case what we did we declare map, okay, what is my key type? I have to convert key type as a string. Okay? The map of string and what is missing value I want I want to have this type list of type. So in the list what I want, I want Okay, listen, we're going to content what leads is going to contain specific key ID or string or anything or we want it should be only collection of object then what object content object and I can give my name name for the video.

Okay, the same thing I did like this. The map of string list of contents so now, this is going to make me something like this. And let me show you that it is going to create exactly one map for me And in that map we can see is going to complete one map okay? So it is going to be two Part one is going to be key and one is going to be Hello. Okay? And with that Okay, so this part is going to be key or this part going to be my demo.

And here are key type of what is a type of string and he'll tell us what the illusion least of like collection element is a collection element. That means let's see, I have one specific he No, okay. Let's see. account one. If I say account one what elements can be? It is going to be collection, so nothing word.

It is again going to be many lemons. It's like Okay, so in this case, my account, let's see, I will take thing I will take it as a by account ID what's your replacement? I just specify here my account etc is okay. Then there are contacts who are going to be let's see contacts nothing but nothing but are Sunni nothing but that is like that, okay. So when you come to here then you can see this thing. So it's a collection which can be so to maintain that we have specify the code like this.

Yeah. And it can be done as efficiently as training. No, perfect. But now how we can give them Hello here. So see, see him If you go and put it is econ map dot put. So what is going to make keepers.

So now let's, I want account ID to be my key so I to con dot account ID. Okay? So now with this, what is going to be though my value, my value is going to be leased or rented. Okay, so now it's one contract. So I want at least up until current, and how I will do that. So now, in my list, I don't have anything I got, okay, this is my contract.

Let's, let's explain the SEO always you have to manipulate this map like this. It's very important thing to understand this how this map happens here. Okay. So now, let's assume I have account one, okay, where I have contact called contact one, contact two, and contact to three contests a year. Okay. So same way, I have one account Did I have contact for contact pi and contacts?

Let's see I have another account which we call account three and then I have contact a contact nine and contract then so that means this is if you see it is nothing but going to be one map for me. Okay. This is nothing but one key. And what do you see this main Hello? So if you specify here is going to be like this right Am I correct here? It's nothing we're going to be three different elements or one key But now, how we'll build this to replicate.

So now see, initially when a query, I could get all this contract code for me. So this content query, returning me. Contact one. Okay? Contact to like all the contracts, what I have everything I've got now. Instead of a string Can't we use ID, we can use ID, anything.

So this ID can be defined as a string, also. String anyhow, it's a string, but it also can be referred to a string if you want, you can write also ID. Okay? For the safe side, I use string because I will get many methods even like anywhere you want. I administering app is class method. So to use that formula in the practice, we use string, but we can use it also without any issue.

So with string data type can we pass ID that means as you have, yes, yeah. Okay. So this ID in this this string, an ID are interesting. So we cannot convert a string to ID but Id can be converted to a string. Okay. So I have this I, whenever this query, I got this context it associated their accounts.

Okay. So now, when I want to put in a map, what I want to pass I want to put account ID nothing but this one I want to poker. So now in the content, I can get account ready, but now if I want, it's a list of filament. So my element going to be a list of content. So it's not a one content, I can make one contract so I want to have a list of content. So on these what I need to do, okay, it should be something like this.

Mr. content for let's see call list equal to new list open taxi I writing wrong Cora okay i liquid How can I think boo to come here? So on this con list Yeah, tomorrow something like this, okay then I can add this code, see if I do that. So now with this account I got some list delivered cert getting a point so now I took one contract let's assume contract one came in the loop I will create a list I added that in the call list and a manipulator. Okay. But when I'm coming to contact to, again create a list or in call list or overriding it so it should not happen like there so I should check. Let's see past point I came I have only is your contract one.

Second thing when I'm looking on the second contract it should check if associated account of this content, nothing but ACC one you're wondering, then don't create any new list. Just add this contract to in the collection. Same way, if right now I have only this one account account one core account one with contract one and contract two. Let's see. Next element I got contact. Now it will check contact type especially to account to do I have any key in ACC to know if I don't have them create a new one.

So how do we handle that? So now what we do here is we check if, okay, in this account map, account content mouthwatering. Let's see if our contour map is a key map. Where doesn't matter something you remember content ski is this contains key with same account ID. So now after I don't have any account ID if it is not contents and what I will do if not contents, then I'll pass time will insert what new key in this map if account content scheme means that means already I processed I have that key, it doesn't have the Nikon me or I just processes. So, I this is going to accept one element of collection type.

So, what type of collection it is going to accept the collection of contact list I writing like this Okay, so one element added in this list. So when second time I came, I will check my map contains any account. Okay, so the second contact if it contains that means already in the map I have your cc one contact one. Now what you want to add in the collection the second element, okay, what I will do from the evil pirate gate? I know you're confusing here. I'll explain Computers slow slowly Don't worry.

We'll write it then flowchart boys are listed the gate if a fire this one what I'll get is a pile this one I will get for this account ID what are the contact list I have? I may have all the two or I may have one party's their thing but I'll get my name Hello stage for a new file the gate. It will give for that key what connection I have. Okay, so literally some simply I'm doing dadada for the new element, whatever. Okay, it may be confusing for you let me know if the confusion is when this for the video. Any question?

That didn't get part if you could just explain what I mean. Okay, so anytime you say. Yeah, can you repeat it again? It's perfect UPC Many times right like this, okay? So how are we officially like any program you see why are we sitting in a map that keeping a collection of elements even matter declared like this? Okay?

We don't need to tie it six seven line score to are the elements this in this type of map so we just write this nothing so how we do that? If you go here let's we'll go by one by one. Okay, completely closer I'm going to use No. So in my contract, I have this medicals okay. So, I am writing contract one, okay, which means I have contact one means first name, last name, everything is their account ID also their each contact whenever saying contact one, it contents everything. Okay?

So now what I do here, so when a query, I'm just making the execution here, okay? So map string lease contract is gonna be shown when you record this line in nothing but in my memory. There is one memory location. happen where the fellas name is correct. So, let me clear this. So this this learning to understand others nothing can be done so because he even understand so in all program will see like this stuff so immediately one memory loaded like this and the name he was given us a sec gone yep okay for now this element what we have now we're going to divide it into part so what are dividing someone with said are the key okay one we said as random okay this is nothing word, the name I get what is the key of my map is the type of string and this is I specify my value, value type of lease contract the moment We have written this line in the back end in the memory in the heap memory we got with the lock here.

Yes, perfect. So now then we came to this line. So this line just the only displaying the highlighted line. So any question on this line, it is nothing but we are calling the contact for a specific account. Okay? credit scoring the contact, if we go let's see, I didn't give any account just I'm putting everything here.

I'm just going to query all the contacts. any confusion on this additional? Okay, so this is okay, what I'm writing, it is going to query me all the contracts. So if I go these and you put in the editor, if you see, I'm going to get all contracts like whatever I have in the system all 20 contracts Okay, let's see. I'm just going to do that i'm just going to do here, account name printed pins. If I do this search settings, I sorted so you can see with these two accounts, I have these two with this one account I have to contact here or here see I have one account united around gasca.

I have this potential there. Okay, even you can go by it. So I have this liquor store the moment I've had this way I got all the contracts. Now I want to keep in America, who should identify for which account part of the contract I have. Okay. So if you see the example alerts is communication is one account for me is communication.

So now I want the content To his communication, like these two, okay seen and Rose is going to be in this collection. Okay, so let's see what happened here. So now when you look it, okay, now on this look how many contact came each time for each contact, you will make a loop here. So for each contract he went inside, now you check it. Okay, so this line now it usually comes to this way. So my map contents in the key account ID or this content.

So now you will check in memory on this map. Do I have any account as a key in this map? Tell me Do we have anything now? So we don't have anything right number two, my map is complete empty. Yes. In my map that is contents key of this account is not there.

So that means this economy Until then I will come to inspect. Okay. So the woman will come to expert. Okay, so now I say my account. See, Cory what I'm firing is going to execute this way. Let me write this in the Laconia pair, and it's going to return me contract one, okay?

So let's contact to for contact by the contact to the contact seven, okay? Let's contact nine contact with three contact for contract taking 21 on on you, so like you say God, so out of these, this contract one making the person you make it you understand contract one, contract seven and the contract 110 belongs to one account okay then Let's see, I switch back on one. So now Same way, I just go to contract five, contract nine, and contract two belongs to account two. Okay. So now, this choosing a subject and or the other other content belong to a country, okay, in this query like in a database database. So now I saw the cool new password time when I came to this flow, I signed the contract or in the contract map, I don't have any key.

So this line failed, then it compiles but now I'm trying to put a new entry on my map. We're going to try we're going to put a new entry. Let's see what kind of entry number this is when new entry. So what I'll do here, so my key is going to the account ID. Let's assume for trickery past I got contract one. So what is my account already?

My Account was Nothing but I found one. So I forgot. Okay, now, in this map, I'm going to put Hashmi, Kiera Coco, and then import valuably, and see the value of this map is the least collection type. That means I have to allocate some memory to there is a collision element some memory should be there. So what we'll do here so I'll create a new list of content mauriello Sunday and in my list, I can have many elements and decrement by name. However, in the memory, I initialize, the list, which may pass contacted me nothing but on the list, I went and added partially made contact one one pass wanted loop, it happened like that.

Any confusion? So, if not displayed, I can do so any convenient on this line. So, with the list, then we can initialize and we can put new list. So, what we did here, see two of them. So if this is making confusion work, so what we can do normally, but not to be confused first, so, I wrote a list of contacts, okay, let's see college equal to new list of contacts. So this line no confusion here, we can declare a list like this.

Then on this list, I can add one specific memory 131 11 don't lead with odd and then I can look on then this list, I can add here with lists numbered my list of contacts, who is needed here. I can do like this also for it. So up right like this. No conditioner. So all the To lines and allocating the memory, everything I just replaced in one line, which I wrote like this. Okay, so see, I don't want to store this thing in my separate memory, just I mean, you're storing in mind map memory.

I'm storing here on this on this path. If I do I need to create another collection list. To keep the data I don't need this under collection lists. I don't need to give some reference to somewhere. So here what I did, simply wrote like new list what type of list contact type it does see this, but I don't want to give any reference and I directly initialize at that moment, instead of adding here if I do this, okay, that means I added my past limit. So with this line, okay.

The combination of these two, okay, so this anchoring, I just joined and rip the structure, the way the players So these two lines are more useful Okay. Now for the purpose of keeping good and committing it okay honestly quite right got it confusion are all okay okay so many people are clear this line not clear okay tell me your What is your confusion just repeat again okay so you know if I want to add any value Tamia What do we do? My map name dot food Okay. Then what is my string value? The my key value key and what is made him correct. So now my last name is nothing work This economy okay then I use food I want to add a new trigger.

So now what is main key I want to use as a specify my key is going to be account one. So, can I say my key? Nothing but from the content for me account ID is what I call it already. Here I get my key, then what is it Hello going to be? Men hello this type of leased up listen for it. So least no collision when I say can I write something like this list of contacts.

See when they look not only to date this but can I use this one directly. So it's an empty list, but I want to add an element like this I wanted to one in this list. I want to add a limit. So we know to add a limit. I have our method And what I want to add this list if you will like this, if it is that then this is going to be mine in the in the end, because maybe I do Fallujah type of List of content. And what it is called is called is also a list of content.

So in my map, so finally, I'm adding the key as my account ID and my contact list. This these three lines clear or not? Yeah. Okay. So now see, you have two options. Okay.

If you don't like these kind of rise test center segment, what I retain employees what you can do, okay, I'm just copying all these things. This one also you can write and manage it. Okay? This, this will work. What I'm trying to do, though, this is the actual code and others are leaving in that way. So now, this was clear.

You can write this way simpler. Okay. We would have written this way, it's likely he would never Express pendulum, but it's fine. We have a tradition. So what I did in the code, instead of these two lines that I replaced with this method, I look at the memory and I initialize the random number despite I allocate the memory to my list, I added past element to the list to the current list. So I don't need any separate column lists.

So what I need I just allocate a list collection of memory and keep the past element and that is going to remain and it was like one of the things as well for me, no issues, okay. Yes. Yeah. So now, I got my contract one, it was not in the key map, then. So are you going and they make created this map. Now, in the query, I have got Kontakt five.

To see. I went to contract by contract five is associated to future Contract a master account. Now I can my account contract nothing but this map contains any key with NamUs account. Do I have any key account? Oh no, I don't have. So again I came to this effort.

So now I create a collection of lease okay. So what if this was supposed to be about 11 in the system, it will create one list collection, okay. Let me write here it will create another list collection for me a list of contact okay. So, yes, I so you have put the curly braces so there is no I mean nothing. Yes. Yeah.

So, we need to assign an instance of that least. You least contact your curly braces called nothing, nothing at all the alternative of these two lines Okay in that they also imported more we can do we can remove this also from here here also directly you can write also that okay that also you can do all those different admin it means add methods that one this is are we even we could see putting you declare integers number one and write so many piece of code then then go and write number one equal 10 you can do this one for some time you also directly do number one equal 10 also, but both things are same. You do this one or letter offender Hello same thing. So, this NFC I look at the memory and then I read hello to this Oh no. So, what is your adding add method?

Yes So, those are one small example you will go to buy vegetable So you will go to one syrup, buy a bag and then go to a tool shop by the student put this okay? Or you go to a real Empress, okay? bring to this table. Okay, they will give you some bags to keep him from come it's like your best basket something that that one family okay. So anyway you can do this one. So now I went to this contract to okay then my contract pay I saw my contract pipe not contents in the map they can they can this theater collection and I added here as I count to have my Kontakt five, okay.

It came like this correct. So how my program isn't going and then I came to contact to Okay. So now if you see my contact to associate position. So now my second look shuttered to contract to I came here my in the door Have any colony account with neighbors account to this make contact to associate to account to Do I have anything I came here? Yes, I have one place this one account I have already Okay. Then that means I just satisfy my condition I came in said this.

Okay, then what I did here from this map, if I do get just do this, okay, let's see I don't have this. If I do this thing, what do you get? If you do get from a map with a key, then you will get a certain value. Nothing but we'll get this dispatch get method of this account to is going to return me this collection of contacts. Right. So remember, continuing on Remember, you know this one now?

So if we write this one, you just didn't make this. Yes. Okay. So if this is a list and you want to add another element with this config name or what contact to correct Mockingbird you're going to add some value on this list. So, if this line returning a list and to add a new element what do you do add to this list what I have annoyed that I have something called are that are they added. Now see, so, these highlighted line determine the least and I have added one more element to that so that it came like this for now you can hit icon to have two elements like this.

It will process each content item tag it correct. Yeah, did so now see, I did so many stops to manipulate this way. Okay. Now see, I just remove all this course whatever I have. I just had a communist Colorado in our initiative how this is edited. This is almost to corrugated.

And they do all the stuff says how many how many things how many lines of code. So now I will convert this piece of code to my recent security. Okay? So I want to query all the accounts and their associated contacts. So what I'll do here, let's see, this is only a one to one vote or a listen simple Report. I'm going to do here see, so I'm just writing here.

List of account. Okay. This is a list equal to I wrote here, select ID. Okay. Let's see if I have an account name named from account if I wrote this Well, I got account details from all accounts. But now I want to get all the associated contents nothing but if my account is the master and my contact so so get account and their child also so if i I'm just writing the query on the account level.

Now, on this account level, every moment I'm writing on this account level, then what will happen for now from this account level, I will have the query, I will navigate to my child, and I'll get their record also. So in this thing, we do parent to child query. And when a query on the child and navigate to parent we call child to parent query. For any child dependent query, we use field relationship name, custom object, underscore, underscore or otherwise Filipina, we're going to come from parent to child. You see here I have one to one relationship field, which we call child innocentive. Now, let's see.

So here, he will go to the View fields on the subject. It will go to any relationship field, every relationship he'll have a attribute which you have set as child and assumption. So this name we will use to create Okay, so if it is a standard object by default I job if it turned out Jake in my parent object name is account okay? And my child object name is contact then it is going to be by default like a standard it's going to be context. So one upon have many contacts, okay? If you want that you can change from this relationship then what is the lesson signal that is going to be used on you?

So you can go to the contact here. Let's see I take the contract example. So I'm going to this contract field okay. It will go to his contact field I have a listen see which account Okay, these are the standard days and see what I'm doing here means listen pseudonymous context. So that way, here I am, privileges is a standard, but if you want custom, listen, you can meditate about important anyone. Okay, now how I can write the query from Master to gave my child Ripper together what I do here I came here.

So, I added writing as a sub query here okay. So, I wrote this here then again what I want I want the field from my content to contract What do you want I want contact ID you want contact last name, I want control class name Okay. Then from where you do not specify the object name you will specify my relationship name. So, what is my child relationship name, contacts, get the account and get contacts records of that year also if you want to confess very well condition whatever user account or so you can switch with a file permissions. any confusion if I do this one. Now this query is going to return me all the records of my account and their contents.

So see to get it here who I hired Cory to tense okay, but here One query I will fire which will give me all the results and incompetent in law. So, what is the best practice dip parent to child or child to parent? We see that is depends to what you have and where to believe See, if you have account details and you want to query the child, obviously you will use for entertain and you don't have account details, you have only the contact name, okay, this is the contact. Then you let's say for example, you know, there is a company called Capgemini you know company name so you want to see who are working in the Capgemini is Salesforce developer, or do you want to see something else for their cap Gemini? Let's see what is the HR people's or their or maybe what are the revenue structure they have equals the current Capgemini and from then to get the child records like for my Salesforce developer Something then you will hire from parent to child same way if you have child labor okay there is a guy named Mr. Sweeney who works in captivity.

Okay I want to get the captivity international so let me I want to get us up to any contact number also okay from the asuni in from a cell I'll go okay Austin he will have to own this company and this time we have this field that doesn't go from child to parent. No, it's not both are not replaceable okay. It based on requirement you can use any of these things. So, from where you have data and what you want to get. Now, you probably want to put this in the map or they can do the I do the math Hello, okay. So now I have a count SEC is the list now See, this is a list who these are called going to contain one upon going to contender all the results.

So simply what I can be here, the if the if this is my map I have okay? You hit the map I have I want to keep this data here simply I can do it is the Konami Code Okay, this is a.id then ACC dot what is medicine sim my sim Neff is content so sama Khan may have or may not be here if it is there then I'll put it put it like that. Even I can be an alternative anything. Okay? So this is going to give me all the records. So now it's a collision record lottery order process.

Again, you can add a for loop to get each contest and get the field names. Okay, so now see if I'm just going to write this query in Developer Console. In the my executed I just wrote it integrated. I got my contracts the contract ID last name, first name all the contact information upon information. This continuity mode as released here, or any confusion assuming I'm good Okay, perfect. Okay, so we got this.

So now let's write a very small trigger to see what more thing I can do in the trigger. So now I want whenever you go and manipulate the account, let's see, the moment you go and in the account it will call number of locations. So how many number location you enter that many contacts, you will insert it in the botto Doosan I'll write this code. Okay. So let's say not in this is not in our location. I can let's see.

I'll just write create a new field, try to make confusion. So I'm just creating a new field I have a number of employees for lightning. So, I have a number three, I want to populate these three Okay. So now I have filled with employees. So now let's see in this employee field now from India I want 10 employee okay. So if I say 10 employee that means I should have 10 contacts.

So, the moment What do I have? I should see injected that many contacts on my system, there is many keyword analysis forums, I should have exactly we are looking for you. Okay. So now he four minutes is 400. So, if I come and modify the account and put the value as five, let's put the value is five, then, by default I'll create one contract in the system. Domain Controller I configured the PI controller.

So if I go on add a new content, I create a new contact record. So automatically there will increment India in the account number of employees and if I delete that will reduce so that kind of trigger I want right. Let's see how I'll I'll complete the trigger for the account Allah. Allah Do we have it in one particular country? We have it in many courts from here and there. Okay.

So this is the knot looks good, no worries, we'll see for that what what we can do. So now I have 10. I want to find over abducting the number of location field I want to manipulate. So now see, I will and I wrote objects so pass when I'm doing the object. So whenever I'm going to update this account value, whose revenue number of employees field when I'm updating these, I'm going to create a contract. Okay, if I'm going to make Type 216 one content I will create it I'm going to make it two three then two content delete and then gentlemen into contracts okay to understand our programming so now that means when a modifying the account I'm going to modify in some record in some other object.

So, now let me tell you you guys tell me which event I should write here. That logic, I am going to do a push event after update, perfect, so now after update, I am going to write some events. Okay. Now see these bits of logic what I have written it's completely in before insert that you want to include nothing else. Simply Can I use my trigger control variable to exclude it See, this is not the best practice write the trigger. I don't write this.

I have completely trigger design pattern. Okay. So that's that you can digest now it's a very lot of thing. Okay, so just to make you understand the trigger and how this trigger motivated, I'm writing here, okay? So I haven't triggered it in between videos also I and the evening sometime in future I will discuss about that. Okay.

So I see right here, triggered dot each before and trigger dot insert, okay, then I just go and execute this piece of code here is not before insert, I don't do anything. And what I'm going to try, I'm going to do the logic right now to a decode only in the afternoon. So it says trigger.is after and trigger.is a bit. So the logical idea so what are the I want surpassing a number of years Place to change. It may be increased or it may be in decrease the flow I'm talking now your logic, okay? interest then are the contract if decrease then delete contact.

Okay, so how will do so now I should see as I always remember we should write the trigger in bulk. Now, if I go and check, if I have a list of accounts it's going to come to me nothing What I can say is triggered at New. Okay? So for each account, there are no new going to give us the collection of elements. Okay, with a collection that remains triggered new. So for you.

I am going to orbit five accounts on the out of hyper phones. Let me show you here. I'm going to Update right now hydrophones okay. So, this hydrocodone we went over it. So out of these five are gone it may happen only on this to account I have the number of employee field change not on this and I will see who else just only I'll take that account to be substituting my logic not others apart I can do for now, for each account I will check if my account which field the field name callers number of employees see here I will call number of employees leave in each account by number of employees changing how interchanging So what was the Hello in my database okay. If you see this account now in database if I look if I go on Edit, let me make a duplicate of that.

I have database value is by now I go on a date and I modified the menu to seven. If you see we compared these two got this new record. And this old record that you change in value five minus seven or seven minus three, the two, they change, they change and this need to be taken care. So the new record I'll get him triggered the new the old record I get into the old employee number and the new object time. So we have triggered a new weapons are an old map. So can I get this record with their ID as a result old map is the ID cn, n equal to one LS.

So here are those same records ID. So can I get this record integrated new new map and this old record integrate old an old map? I'm getting it. Now if you see here, I got the trigger a new the new record I have nothing but we're entering into a new segment. Okay, from the east the number location field is the same as old record to get older for what I did. I did triggered the old map from the world map I want to get the specific record.

So who is your target for the same ID so if you see This new record ID and old record ID or this ID and this ID isn't Okay. So now I'm getting bearish on that if there is any change then I will consider that so I will see for that account how many contacts are how many contacts are going to be insert or delete depending on positive and negative. So I'll just create one nap here I kept them Hello was string nothing but my account ID okay. And they gave the integer nothing but my number of contacts will be inserted deleted. Okay, sec, number of employee employee map, new map of string integer inconveniently law can I take these and I do simply put dot food so what I want Do I want the acc.id semi quad value I'm going to hear. So what is the difference?

So now, this is seven. The new record I'm going to insert an old is going to be Hi, seven minus five refer to that when I'm going to insert two new context. So can I do that like this? sec number map. Let's, let's just make a simple definition. Okay?

If I'm just trying to handle the knowledge on all conditions, if sec DOT number of employees not equal to null, the new hello what I'm going with is not not I'm just handling that. Okay. And then Okay, also not null. Then let's see. integer, employee count. Report.

Judo initially. So I'm going to do my employee count hammers, if the different scenarios are and styles, I'm just going to handle it. So on this trigger dot old map the number of employees field what I have compared it here if you see these holes now for number of employees here, if this is not empty so before it may happen before I don't have any value, you're fine, nothing is here and then all value. Now I'm going to put seven seven minus all that logic I haven't checked, okay. Now these sec the number of employees if not equal to null, then my conclusion will be based on this so my employee count what I have equal to the new hello what I have nothing but seven minus my old And he previously if I have this value, previous value if it is blank, you'll see I don't have anything that means null.

So now I'm putting seven so seven minus null nothing but it's seven I want to put so for that reason I wrote like this if my whole value was not in all this, it's all value was not my employee count will be the new value what I have nothing but dispute Okay, and if I say there is no change, I am not doing anything. If there is a change a new value is not not going to thing and eat my new village not let's be four. I had the seven here. Okay, so now I'm just going to be four out of five here. Now I'm going to delete nothing. So it's zero.

Okay, so it's not even all for me so normally I'll say it as you know if my current number employees no not not me, nothing but ignore like somebody else. Simply I said employee count the quality of God what I'm doing here this employee count I'm nothing but going and putting in the work. I just have a Discord. Let's see. I just have to give some semicolon some area semicolon here any confusion unclear Okay, now we got okay I have to create the number of contributions so we'll see how we can be here. Okay, go in my update for voice on Twitch account harmony.

The course I have to create I understood Okay, now I go here for my number of accounts I kept. Okay. So far. Let's see I specify a string, sec iD iD which is my Key that piece it when when I do this one. Now, for each account how many contractors did depending on what is custom listen can your employee count? Okay, so now each integer start from zero to take my all employee count maybe I will create one contact record ponder I just put the last name of singles.

Okay? Yes Can I Okay, then I want to go on the database only once. So I just create a collection of content. So I'll add all the content in one place and I'll go on the database to insert them Okay, see now I am you know, on these I deserved Connolly's third con, but this will happen when, if my count is greater than zero, you may encounter this and you know, I'm not going to insert anything new. But I just kept this fancy. I'm not going to complete this quote today.

Okay? So this is me, flow what I'm what I'm doing now, but my point so you were the thing, the logic what you can do so tomorrow, we'll come to this

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.