In previous tutorials you created objects that stood more or less on their own. In this tutorial, you create a Line Item object and then relate it to both the Invoice and Merchandise objects.
You must complete all previous tutorials in this series, starting with Quick Tutorial 1: Build a Cloud App in 5 Minutes.
The last time you created a custom object, you created an associated custom tab right away. Because line items should only appear within the context of an invoice, you don't need (or want) to view line items by themselves, so ignore the option for creating a tab.
Every line item needs to track the quantity ordered. So the next thing you need to do is add a Quantity field. You already know how to do this — simply repeat Step 3 from Quick Tutorial 2: Build A Cloud Database — Add Fields to an Object.
An invoice can have multiple line items. To create that relationship, specify a new field as a master-detail relationship.
The other relationship you need to implement is called a lookup. As the name implies, the field gets its information by looking it up dynamically in another object. In the last step, you used Save and New, so you should already be on the New Custom Field dialog.
Accept the defaults on this screen by clicking Next, and on the subsequent screens by clicking Next, Next.
On the final screen, uncheck both check boxes for appending this to related lists, because you don't need a list of line items on the Merchandise page. Now you can Save.
Now create another invoice to see how these relationships work. Click the Invoices tab and then New and Save.
Notice there's a button to create New Line Item. Click it.
For the Line Item Number, enter the number
1, and then click the lookup icon to choose a piece of merchandise. Note that you can also enter the first few letters of a piece of merchandise and when you save the record, the system figures it out for you. There's a lot of built-in functionality!
You now have three objects, several fields, and two kinds of relationships. If you have all of that in your head, awesome. However, most people find this is an ideal time to use the old adage "a picture is worth a thousand words."
The Schema Builder represents your objects, fields, and relationships in a standard entity-relationship diagram. In a relationship, the "crows feet" at the end of the line tells you which side is the "many" side of a one-to-many relationship (one invoice can contain multiple line items).
Note: The Schema Builder isn't just for viewing your schema, it also supports drag-and-drop development for creating new objects and fields. However, unlike the wizards you've used so far, everything you create on the Schema Builder will be invisible to users. You must set the field visibility and configure page layouts before your new objects and fields can be accessible. Field visibility and page layouts will both be covered in a future Quick Tutorial.
Typically, every business app enforces "rules" that prevent bad data from getting into the system. Without such rules, things can get real messy, real fast, because users might not adhere to these rules on their own. In the next tutorial, you will learn how to enforce a business rule in the Warehouse app's database, without typing in a single line of code.