Salesforce Certified Platform App Builder – 3 – Data Modeling and Management Part 9
- Creating External Objects & Data Source with Salesforce Connect and Heroku
So now it’s time to complete this helpful practice activity where we’re going to create an external object and an external data source by completing this tutorial that’s on developer force GitHub IO. And so we left off here on this module two, we already previously realized that we’ve created a free developer account. And so we’re in module two of installing the Schema package. And so to install this, you just click this link that says clicking here, and that brings you to this screen. Now, one thing is that I’m already noticing that in this tutorial, it’s saying that’s going to take you to the package installation details. The main thing to keep in mind as I go through this, I’m going to try and keep this brief. And so it might be ideal for you just to watch as I work through this and then you work through it in your own Salesforce instance. Or you can pause and do these steps along with me. But the main thing at this point to realize is that we want to grant access to Admins only for this package that we’re installing.
So if I go back here, I’m just going to accept the defaults of installing for Admins only and then install. So it’s going to install and grant access. I’m going to view components while waiting and you see some of the package components. And this will disappear once this is installed. But you see VisualForce Page, some Apex classes, a custom tab and Custom field, and then as well, an app that will be included in this install. So I’m going to go ahead and close this out and see how we’re doing on the installation process. You see that? This app name is Lightning. Connect, quick start. You could do a search for that in the App Store or App Exchange. And this is version 1. 1 of this app that’s installing. So while that installs in this tab, I’m going to go back to my tutorial tab and scroll down some more. So we’re installing and then it looks like as well for this tutorial, they’re wanting you to do this in Salesforce Classic instead of Lightning. And so what we’ll do is we’ll switch over to Classic.
So it’s saying that this app is taking a long time to install. And I’ll receive an email after the installation has completed. So I’m going to click done. And then I’m going to go ahead and pick back up once that is installed. So now I’ve got the app installed. And if you look in the tutorial here and I’m in module two, step six, it’s going to click the app menu in the top right and then select External Orders. And this is a new application that was installed in your Salesforce instance by installing this app off the App Exchange. So if I go to my Salesforce Classic and click on the App drop down, you see External Orders is now available as an app in our salesforce organization. And so now if I click on that external orders, it brings me to this page that says Lightning Connect Quickstart and a button to Set Customer IDs. So let’s go back to our tutorial.
And it’s saying that we need to click Set Customer IDs to assign Customer ID numbers to the sample account records in your Developer Edition. And so I’m going to go back here, click Set Customer IDs and it says that Customer IDs have been successfully assigned to account records. You can now do the lightning connect. Quickstart. So going back to the tutorial, it’s saying that my Salesforce Developer Edition is now set up for the main section of the tutorial. It’s time to integrate some data. So we’re clicking next. We’re now in module three, where we configure an external data source and external objects. And so in step one, we’ve seen structures here to log into the Developer Edition, which we are, and then we need to go to the setup menu and find external data sources. And so I’m going to do just that by going to set up and doing a search for external and selecting external data sources. So now we have no external data sources set up in our own salesforce account currently. So if I go back to the tutorial, we’re going to enter Order DB as the label, and then we’re going to select Lightning Connect OData 2. 0 as the type. So if I go back here, I’m going to select new external data source. And then for the external data source, we’re going to enter Order DB for the name and external data source. And then for the type, it was Salesforce Connect OData 2. 0.
So going back to the tutorial, we want to enter this URL as the URL for this data source. So I’m going to copy this and I’m going to go back to my developer. org and then enter this for the URL. Now let’s see if we need to select anything else. So this shows you what this should look like. We’ve got our URL that we just pasted and then it looks like the defaults here. Yes, it says leave the remaining settings with their default values and click Save. And then one important note is, since this is a sample read only database, no authentication is required.
A real external system would likely require some credentials. And you can configure Lightning Connect to use the same set of credentials for all access to the data source or separate credentials for each user. So the thing to bear in mind is that this address is just a read only database of data and doesn’t require any credentials, so it’s wide open to the public. So I’m going to click Save as it instructed in the tutorial. And so now we have created an external data source called Order DB. Now going back to our tutorial, under step two for create external objects, it’s saying to be sure that you click Validate and Sync. So what that’s referring to is just making sure that you’ve clicked the Validate and Sync button here and that brings up the next screen.
So now we need to select Order and Order Details from the list or the table on the screen here. So we’re going to select order details and orders. And now finally we’re going to click Sync. We click sync here. And so now we see the external data source for Order DB. And if you scroll down, you see under External Objects, we’ve got Order details and orders and those have been validated and we have synced those. So the next step of the Tutorial is step three is where we inspect the external object configuration. In order to inspect this external object configuration, we want to click on the Orders link. So we click on Orders here under the External Objects Related list and that brings us to the external object for Orders. So that’s one of the two external objects that have now been created. And then in this tutorial, it’s noting that you need to note that the suffix for the API name for an external object is underscore underscore X rather than underscore C.
So let’s take a look at that real quick. And you notice that the API name is Orders underscore underscore X as they mentioned in the tutorial. If you scroll down, you see some standard fields and some custom fields here. And then a page layout is created as well. A compact layout, search layouts. A lot of these things come by default when you create an external object and then even buttons, links and actions. And these are all standard whenever you create a new external object. And so I’ll let you review the rest of this part here in the tutorial. So one other thing that they’re talking about is the Display URL. And that has to do with this standard field here in the tutorial. Or it’s this field right here. And the field label is Display URL and that just holds how the URL or website address appears in that field. So now we’re ready for step four in this tutorial, which is to create a custom tab that does enable you to easily access order records. So we’ll go ahead and walk through doing that as well.
And then we’ll complete this by viewing the external order data. So to create a custom tab for the order records, we’ll go to Set Up and then click Create Tabs. And then we’re going to select New under the Custom Object tabs. So I can actually just do a search for tabs and then under Create Select Tabs and then under Custom Object tabs, as it mentioned before, just click on New. So if I go back to the Tutorial, it’s saying that we want to select Orders as the object and then select a tab style. So for the object, we’re going to select Orders and then for the tab style, we just need to select a tab. I’m just going to select the Ticket tab style. You can select wherever you want. Then back to the tutorial. We need to click Next a few times. So for the tab visibility, we’ll just leave that default on for all profiles and click Next again. And then we want to deselect this to not include this tab in all of the apps in our Salesforce instance, but we do want to include it in the external Orders app and then click Save. So now we’ve completed the steps involved in creating the custom tab.
And so now to view the external order data, now that we have that tab available and associated with the external Orders app, we will click on the drop down and select External Orders. And so it’s already up by default. So if I were to click on the Sales app to where I can’t see the external Orders app from the drop down, I just can then toggle back to External Orders to further exemplify how this works. And so this brings up the external Orders app and we’ve got the Quick Start tab. And then the other tab is the Orders tab. But I want to note as well, under this Lightning Connect Quickstart page, you show that the customer IDs have successfully assigned to account records. You can now do the lightning connect. Quickstart. And so for the Orders tab, here’s all of the orders. So I click Go and we’ve actually connected to this external data source.
And the data is being populated in our external object that we’ve created. And then this field that I mentioned previously for Display URL, this is how these appear. So if I were to click on one of these records, that’s the external ID. You bring up the order details and then you can go back to all orders here by clicking that. And so that’s what this step five of the tutorial is having you do. And so what Lightning Connect does is it retrieves order IDs for the first 25 order records from the sample order database. Then as well, it shows you how to click on one of the order details pages by clicking on one of the orders from the list. And so then Lightning Connect actually retrieves all the fields for the order you selected.
So one important note when dealing with external data sources and external objects is that it’s important to remember that external data is never duplicated in Salesforce. Lightning Connect always fetches current external data in real time. So it just pulls it into Salesforce and displays the most current information, but it doesn’t actually write the records to Salesforce. And so we click on Next to Go. The next step here the next module of this tutorial. I want to encourage you to go ahead and complete these modules. Here you can actually configure indirect and external lookup relationships and also you can do the wrap up module for enabling chatter and viewing orders and salesforce one even. This really does conclude this lecture, though, as far as how to adequately create external objects and external data sources. And so we want to move on now to the next lecture.
- Introducing the Schema Builder
All right, so now we’re going to introduce the Schema Builder and talk about it a little more fully than we’ve previewed previously in this course so far. And so we have touched on the Schema Builder briefly and done a few things in it. But I want to delve more deeply into some of the nuances of things you can and can’t do in the Schema Builder. And then in the next lecture, we’ll be doing some additional work in the Schema Builder for our application that we’re creating, which is the IMDb Clone app. So if I go to Setup and recall we just finished up creating external objects and an external data source, if I go to Setup and type in Schema to find the Schema Builder right now, I have nothing selected for the canvas. If I select all, you have all different objects that are in our schema which you can drag around.
I’m going to clear all though. And then I want to show you if you select order and order item, these are the external objects we created previously. Those do not display in schema builder. So it appears that external objects are not supported in the Schema Builder even though they’re listed here. You can actually select from different lists like selected objects.
And those are the two that I have selected now, which are those external objects, or you can select just standard objects or custom objects or system objects. And so a few things to note are that Schema Builder is enabled by default and lets you add the following items to your schema, such as custom objects, look up Relationships, master Detail Relationships, and then also all custom fields except for geolocation fields. If you click on the Elements tab, you can see the option to be able to drag a new object, for instance, in order to create a new custom object. And then as well, you can actually drag different types of fields, relationships, et cetera, by dragging here. So let’s bring a few objects into view here.
And so I’m going to select clear all under all objects, actually, just make sure I don’t have anything selected. And then for our own application that we’ve been building, let’s pull up just the custom objects here so we can see those more clearly. We’ve got episode, we’ve got person, we’ve got production and we’ve got production position. For example, you can zoom in by clicking the plus sign. You can click and drag to bring these into view. And then you can hover over to see the different relationships between objects as well. So then as well, other things that you can access through the Schema Builder are these view options. You can click on that down the arrow to either display element labels or hide relationships, or hide the legend as well.
So, for example, the legend is this item here on the right. So if you wanted to hide this and get this out of the way, click on View Options and click Hide Legend. And so you can toggle that back by clicking Show Legend. And so then as well to display element labels you can click on that and toggle it back to Display Element names. So what that means is element names would be the API names. You notice here the underscore C for Position type. So if I say Display element labels this would be what the end user sees for that field. And so that reads Position type and without the underscore C. And then as well you can hide relationships if you just want to see the blocks for the different objects. But I’m going to put that back as well and I’m going to return this back to the element names.
And so this is better functionality really for developers to be able to see relationships, to be able to see the API names and to be able to work from there. Another thing to note is that there’s no way currently to export the schema builder to like Visio or an image file. I think that would be a great app that one of you guys could build in the future and sell on the app exchange as an aside. But currently that’s not supportive functionality for some reason in the schema builder. So then as well, another button here at the top is the auto layout. So if I click that it makes an attempt at doing an automatic layout of the different objects in the schema builder.
So select all to show all objects. Let’s click Auto Layout and see what happens. And so this is an attempt to do some sort of cleaner layout. As you noticed before the auto layout everything was layered on top of each other. So this is Salesforce’s automated way to do a layout that makes more sense. And you notice here in the center of this or near the center of this, one of the key entry points or center of the bullseye here would be the user record and a lot is connected with that. You see that better as I zoom out and there’s still some layering going on. So at least get you a starting point of what might be a logical starting point, then you could drag and move things accordingly. And as you can tell, these diagrams can get very extensive and confusing if you want to include everything. Now that we’ve discussed the schema builder a little more fully and shown you more of the options available and address some of the limitations of the schema builder, we’ll now do a helpful practice activity where we’re going to create custom and junction objects in the schema builder.
- Practice Activity – Creating Custom & Junction Objects in the Schema Builder
So now we’re going to do a practice activity and this will be where we’re going to create a custom object for our own application that we’re building throughout the duration of this course. And then we’re going to make a couple of Junction objects. Basically, that is a mini to many relationship between two objects. And so we have most of our custom objects in place already on the Schema Builder. I’ve selected the custom object selection from the drop down here and I’m in the Objects tab in order just to show the custom objects. And I’ve selected these top four for episode person, production and production position. These are four custom objects that we’ve previously created. And in this lecture we’re going to create one more custom object and then we’re going to start to relate these objects to one another in order to make some of these objects junction objects. And so you notice here at the top I have the production object.
And this has to do with any sort of movie or TV show or video game. And so the thing about a movie is those are standalone units, one movie at a time, whereas a TV show will have episodes. And so we’ve got this relationship here, this Master Detail relationship between episode and production so that a production could have multiple episodes. We will later tie in the episodes to only tie into productions with a record type of TV show. We won’t have episodes for movies. And so we’ll clear that up later in this course. But for this lecture, we are going to start to connect people through this person object here to productions and then also tie these people to a production position.
So this production position object is actually intended to be a Junction object, tying together the production with the person. So how we do that is we need a couple of Master Detail relationships defined on the Junction object, which is this production position object. But before we dive into creating these Master Detail relationships, I want to have you go in and delete a couple of records from your salesforce instance. So if you right click on Setup here at the top right and open this link in the new tab, that way we can go into the Setup menu in this other tab without losing our place in the Schema Builder. And so I want to go to the Productions records that we have and we need to clear those out in order to add new Master Detail relationships looking up to this production record. Since we already have some data already populated here, I’m going to go ahead and delete these records.
Now, in the real world, there’s a way of getting around this to where you don’t have to delete these records. But for sake of learning and at the point we’re in right now, I want to simplify this process by just clearing out our two records. Since we only have these two. And so I’m going to click on wizard of Oz and delete this record and click OK. And then as well, I’m going to click on the Cheers TV show that we entered previously and deleted as well, and click OK. And then I’m going to go to my Recycle Bin just to be safe. And I’m going to clear these out by selecting both and then selecting to empty my Recycle Bin and click OK.
So on the other side of this relationship are the production position records. I want to go ahead and clear out any that we may have there as well. And so if I click on the all tabs link and then select Production Positions, you can see that we do have one production position that I created previously. I’m going to go ahead and delete that as well. And we’re not going to go into the complexities of why that is at this point. Just follow along and go ahead and delete this record. And just to show you and remind you what that record looked like, it’s not anything important at this point for our application. And so in order for us not to get blocked and created these master detail relationships in the Schema Builder, I’m just going to go ahead and delete this production position and confirm the deletion, and I’m going to go back to my recycle bin and empty my organization’s recycle bin, just to clear out everything, just to be safe. And then as well, I’m going to go ahead and close the schema builder and go back to it just to make sure that the latest things from memory are in place here and we’re not pulling any old data. And that may not be necessary to do that, but I want to just be safe so that we don’t get blocked in creating these master detail relationships.
So we’re on the production position custom object and we’re going to make this adjunction object between production and person. That will be two Master Detail relationships, one looking to the production object and one looking to the person object, both originating on the detail side from the production position object. And so in order to enter into these relationships, I need to click on the Elements tab from the Schema Builder and drag and drop Master Detail onto the production position object. This would be the child or the detail side of the Master Detail relationship. So the first relationship that I’m going to establish is with production.
And so I’m going to enter that for the field label and then I’m going to tap out of there for the field name to also display production, and then I’m going to tap down to, related to and relate this to the production object. And then I’m going to allow the child relationship name to enter the default and I’m going to accept the default for the Read write ability. And that allows users with at least read Write access to the Master Record to create, Edit or delete Related Detail records and then the Related List label. This will appear as production positions.
This is the title that I’m specifying that the Related list will have and all the layouts associated with the parent. And then I’m going to allow these child records to be reparentable so that they can be moved to a different parent or different master record. So now I’m going to click Save to establish this first relationship. The field has been saved and we can hover over here to see the Master Detail relationship from production position to production. I’m going to do this again anywhere to connect this production position object with this person object.
So I click and drag master detail. And remember, we’re going to associate this with the person object now. So I’m going to just keep it simple by just going with the defaults. And this will start to make more sense as you see the app from the front end later on in this course. But the main point of this particular lecture is getting familiar with entering relationships in The Schema Builder and creating custom objects as well, which we’ll do a new custom object here in a moment. So we’re associating this relationship with the person object and then the child relationship name. We’re going to take the default of production positions for that as well.
Accept the default of Read Write for the Sharing setting, keep the default for the Related List label and then select Repairantable for this as well and click Save. And so now we’ve created a Junction Object. We’ve got the two Master Detail relationships on the production position object and that is a Junction Object between a production and a person. Because a person can be on multiple productions and also productions will have multiple people associated with them. So you need this Junction Object called production position. And this object is where you capture what sort of position or role someone plays on a production. So that may be key grip or actor or writer or director, for example. So now let’s talk for a moment about the need for another Junction Object. We just created the junction object between productions and persons with this junction object called production position. And then we also have TV shows which have individual episodes. Now, when you think about TV shows, individuals or persons or people here, they may fulfill one role on a TV show in one episode. Then they could fulfill other positions on other episodes of a TV show.
An example would be someone that serves as a writer for one episode of a TV show and then the next episode they serve as a writer and also appear in the show as an actor. And then in the next episode they could serve as executive producer, writer, director. And so you see the need as well for there to be an additional Junction Object between episodes and people, we can just simply fill in this production position in order to take care of the multiple different types of positions that people could fulfill on TV episodes. So next we’re going to be creating a custom object called Episode positions. So I’m going to drag Object from the Elements tab onto the canvas. Then I’m going to fill in the information regarding this new custom object that we’re now creating.
And this is the episode position entering the plural label of episode positions. And this does start with a vowel sound. And so I’m just going to keep the defaults on the screen and then check here, then finally click Save. So now that we have the episode position object created, we need to enter into a couple of master detail relationships in order for this episode position object to be a junction object between the episode and the person. And so if we click on the Elements tab and then select Master Detail and click and drag into the episode position object, we’ll make the first connection and that being to the episode. And so we will relate this to the episode object and then accept the defaults here. And then allow for repairing of the master detail by checking this bottom check box and clicking Save.
And now you’ll see the relationship line here and you can hover over that to see the master detail relationship from episode position to the episode. So now we need to create one further master detail relationship and that would be between the person and the episode position. And so once again, we’re going to drag Master Detail onto the episode position. That would be the detail side of the master detail relationship and then release to drop it in place. And then for the label, this will be connected to the person object. So we’re going to relate this to Person. I’m going to go ahead and do this first to help us remember what we’re dealing with.
So it’s the person object. And so we’re going to say Person for the field label and the field name. We’re going to keep the read write sharing setting for the related list label. I’m going to enter Episode positions. In fact, I’m going to check to allow repairingable Master Detail that allows child records to be repairing it to other parent records after they’ve been created. I’m going to click save. So now we’ve done a lot in this particular lecture. We’ve created a new custom object in The Schema Builder and that was the episode position. And then as well, we’ve made not only Episode position a junction object, but also Production Position a junction object. We did that by establishing two master detail relationships from these objects. The first one being Production position being the detail side of the relationship to both the production object and the person object. And then for the episode position junction object, it’s the detail side of the master detail relationship.
On both episode and person. And so we will revisit our IMDb clone app more as we progress further into this course. But for now, we’ve set up our objects. We’ve got our schema set for the most part. There’ll be additional things we’ll do later on in this course as far as establishing record types on production. That will be several lectures later. But we will revisit this production object and create record types. That’s where we’ll be designating movies, TV shows and video games in order to segment the different types of productions. And once we do that, that’s where this episode will come into play for just TV shows, whereas the production position will be dealing with movies and video games. So the good news is we’ve now completed the data Modeling and Management section of this course. And so it’s time to move on to a quiz to test your knowledge retention of the topics that we’ve covered in this particular section of the course. Then after this quiz, I’ll see you on the other side as I introduce you to the.