📣 Attention Salesforce Certified Trailblazers! Link your Trailhead and Webassessor accounts and maintain your credentials by December 14th. Learn more.
close
trailhead

Build the Object Model

What You’ll Do

  • Add fields to the Battle Station custom object.
  • Create a Resource custom object and fields.
  • Create a Supply custom object and fields.

Overview of Objects

The Salesforce Platform provides a powerful database, with many features that make it faster and easier to create applications. Unlike spreadsheets or relational databases that store data in rows and columns, the Salesforce Platform uses objects to store data. Objects contain all the functionality you expect in a spreadsheet or database, with additional enhancements that make them more powerful and versatile. Each object comprises a number of fields, which correspond to columns in a spreadsheet or database. Data is stored in records of the object, which correspond to rows.

There are two types of objects:

  • Standard Objects—These are objects included with Salesforce, by default, for example the objects used to store data in standard tabs such as accounts, contacts, or opportunities. So if you ever want to sell timeshares in your Battle Station, the CRM functionality is already there.

  • Custom Objects—These are new objects you create to store information unique to your application. Custom objects extend the functionality that standard objects provide. For our Battle Station Construction app we'll be using Custom Objects exclusively.

If you would like to know more about objects, field, relationships and all sorts of other great stuff, check out our Data Modeling module after this project.

Data Model

Our application will use three custom objects:

  1. Battle Station—This will be our main object that tracks the status of the project, its supplies and resources.

  2. Resource—Projects are about doing "stuff" and you need resources (that is, people) to do "stuff." We'll use the resources custom object to track the number of people working on the construction project and how much time they are committed to it.

  3. Supply—You also need supplies and equipment to build a Battle Station. We'll use this object to track our supplies and their costs.

If you like ERD diagrams, and honestly who doesn't, this is what our object relationship looks like. We're going to build these objects now.

ERD diagram used to display these three related objects: Battle Station, Resource and Supply.

Battle Station Custom Object

In the previous step, we built our Battle Station custom object. Now we need to make custom fields for that object.

  1. Click Gear icon and select Setup. This launches Setup in a new tab.

  2. Click the Object Manager tab next to Home.

  3. Select Battle Station.

  4. Select Fields & Relationships from the left navigation, and click New.

Now we're ready to make a custom field. Let's do this!

Step 1: Add a Project Status field

When managing a project one of the key metrics is status. Nothing looks worse than your boss asking you how the project is going and you don't know. It makes for a very dark day. You'll create a picklist field so that users can select from a predefined list of available statuses.

Create the Project Status field as follows:

  1. For Data Type, select Picklist, and click Next.
  2. Fill in the custom field details:
    • Field Label: Project Status
    • Check the radio button next to Enter values, with each value separated by a new line.
    • Enter the following values for the picklist (one per line):
      • Green
      • Yellow
      • Red
      • Complete
    • Display values alphabetically, not in the order entered - Unchecked.
    • Use first value as default value - Checked.
    • Uncheck the Restrict picklist to the values defined in the value set box.
  3. Leave the defaults for the remaining fields, and click Next.
  4. Click Next again to accept the default field visibility and security settings.
  5. Click Save & New to add the Project Status field to the page layout, save the Project Status field, and return to the first step of the wizard.

Step 2: Add a Weapons Status field

The main purpose of a Battle Station is to blow stuff up. We need to keep track of weapons, primarily the planet destroying type, and what their current status is.

Similar to the Project Status, you'll create a picklist field so that users can select from a predefined list of available statuses.

Create the Weapons Status field as follows:

  1. For Data Type, select Picklist, and click Next.
  2. Fill in the custom field details:
    • Field Label: Weapons Status
    • Check the radio button next to Enter values, with each value separated by a new line.
    • Enter the following values for the picklist (one per line):
      • Not Yet Operational
      • Fully Operational
    • Display values alphabetically, not in the order entered - Unchecked.
    • Use first value as default value - Checked.
    • Uncheck the Restrict picklist to the values defined in the value set box.
  3. Leave the defaults for the remaining fields, and click Next.
  4. Click Next again to accept the default field visibility and security settings.
  5. Click Save to add the Weapons Status field to the page layout, save the Weapons Status field, and return to the Battle Station Custom Object page.

Resource Custom Object

When building a Battle Station you have to have resources to do the actual work. There's no magical force flowing through the universe that will do it for you. You need people, and a way to track their usage. That's what our Resource object will do.

  1. Click Gear icon and select Setup. This launches Setup in a new tab.

  2. Click the Object Manager tab next to Home.

  3. Click on Create dropdown and then select Custom Object.

  4. On the Custom Object Definition page, create the object as follows:

    • Label: Resource
    • Plural Label: Resources
    • Record Name: Resource Name
    • Check the Allow Reports checkbox
    • Click Save.
  5. Now create a custom tab. Click the Home tab, enter Tabs in Quick Find and select Tabs.

  6. Under Custom Object Tabs, click New.

  7. For Object, select Resource.

  8. For Tab Style, select any icon.

  9. Leave all defaults as is. Click Next, Next, and Save.

Now we have to create a couple of fields like we did with the Battle Station. Click the Object Manager tab next to Home and select the Resource custom object. Select the Fields & Relationships section and click the New button.

Step 1: Add a Quantity field

The Resource Name tracks the type of crew we need (e.g., plumber, exhaust port inspector, massage therapist) so now we need a field that determines how many resources of each type we need.

Create the Quantity field as follows:

  1. For Data Type, select Number, and click Next.

  2. Fill in the custom field details:

    • Field Label: Quantity
    • Ensure that there is always a number entered for this field by checking the Required checkbox.
  3. Leave the defaults for the remaining fields, and click Next.

  4. Click Next again to accept the default field visibility and security settings.

  5. Click Save & New to add the Quantity field to the page layout, save the Quantity field, and return to the first step of the wizard.

Step 2: Add a Utilization field

When resources are working on a project they might not be committed full time. They may work 50% on one project and 50% on another for instance. This is a resource's utilization and it's important to track when you want to look at metrics and scheduling.

Create the Utilization field as follows:

  1. For Data Type, select Percent, and click Next.

  2. Fill in the custom field details:

    • Field Label: Utilization
    • Ensure that there is always a percentage entered for this field by checking the Required checkbox.
  3. Leave the defaults for the remaining fields, and click Next.

  4. Click Next again to accept the default field visibility and security settings.

  5. Click Save & New to add the Utilization field to the page layout, save the Utilization field, and return to the first step of the wizard.

Step 3: Add a Battle Station field (Master-Detail Relationship)

Resources are assigned to work on a specific Battle Station so we need to create this relationship between the objects. You'll be creating a Master-Detail relationship from Resources to Battle Station. This creates a special type of relationship between two objects (the child, or "detail") and another object (the parent, or "master"). Master-detail relationships can be used whenever there is a tight binding between two objects. For example, consider a blog and blog posts. If the blog is deleted, the blog posts should go too. Plus, the relationship provides all sort of extra benefits. We'll go over one of those in a second.

Create the Battle Station relationship field as follows:

  1. For Data Type, select Master-Detail Relationship, and click Next.

  2. Select Battle Station from the Related To picklist, and click Next.

    • Field Label: Should default to Battle Station
    • Field Name: Battle_Station
  3. Leave the defaults for the remaining fields, and click Next.

  4. Click Next again to accept the default field visibility and security settings.

  5. Click Next to add the Battle Station field to the page layout.

  6. Click Save to add the Battle Station field to the page layout, the related list of Battle Station records to the page layout (we'll go into more detail in a second), save the Battle Station field, and return to the Resource Custom Object page.

Supplies Custom Object

This brings us to our last custom object. To build our Battle Station we need supplies and equipment such as cosmic wave generators, donuts, armor wax, laser guns, mustache wax and such. This stuff costs money so we want to track our costs to make sure we stay under budget and are not called into the boss's office.

To get back to Object Manager, click Gear icon and select Setup. Click on Object Manager tab next to Home. Click the Create dropdown and then select Custom Object again to get started. This should feel very familiar to you by now.

  1. On the Custom Object Definition page, create the object as follows:

    • Label: Supply
    • Plural Label: Supplies
    • Check the Allow Reports checkbox
    • Click Save.
  2. Now create a custom tab. Click the Home tab, enter Tabs in Quick Find and select Tabs.

  3. Under Custom Object Tabs, click New.

  4. For Object, select Supply.

  5. For Tab Style, select any icon.

  6. Leave all defaults as is. Click Next, Next, and Save.

Now we have to create a couple of fields like we did with the Battle Station. Click the Object Manager tab next to Home and select the Supply custom object. Select the Fields & Relationships section and click the New button.

Step 1: Add a Quantity field

When we order light bulbs or armor wax, we need to track the quantity.

Create the Quantity field as follows:

  1. For Data Type, select Number, and click Next.

  2. Fill in the custom field details:

    • Field Label: Quantity
    • Ensure that there is always a number entered for this field by checking the Required checkbox.
  3. We want to encourage our users to order at least 2 of any supply (we always like to have a back up), so we'll set the default value to 2.

  4. Leave the defaults for the remaining fields, and click Next.

  5. Click Next again to accept the default field visibility and security settings.

  6. Click Save & New to add the Quantity field to the page layout, save the Quantity field, and return to the first step of the wizard.

Step 2: Add a Unit Cost field

We also need to record how much each unit of our supply or equipment costs. For instance, if we order 1,000 inflatable bath toys we want to track that they are $2.75 each.

Create the Unit Cost field as follows:

  1. For Data Type, select Currency, and click Next.

  2. Fill in the custom field details:

    • Field Label: Unit Cost
    • Length: 16
    • Decimal Places: 2
    • Ensure that there is always a number entered for this field by checking the Required checkbox.
  3. Leave the defaults for the remaining fields, and click Next.

  4. Click Next again to accept the default field visibility and security settings.

  5. Click Save & New to add the Unit Cost field to the page layout, save the Unit Cost field, and return to the first step of the wizard.

Step 3: Add a Total Cost field (Formula Field)

Now that we have the quantity of each item and the unit cost for each item, you obviously want to know the total cost for all items. Instead of manually calculating these costs (quantity * unit cost = total), you can let the Salesforce Platform do the work for you using a Formula Field! These fields are calculated at run-time much like formulas in a spreadsheet. They make life sooo much easier.

Create the Total Cost formula field as follows:

  1. For Data Type, select Formula, and click Next.

  2. Fill in the custom field details:

    • Field Label: Total Cost
    • Field Name: Total_Cost
    • Formula Return Type: Currency
    • Decimal Places: 2
  3. Click Next.

  4. Since we want to see the total cost for each supply record, enter the following for the formula: Quantity__c * Unit_Cost__c, and click Next.

  5. Click Next again to accept the default field visibility and security settings.

  6. Click Save & New to add the Total Cost field to the page layout, save the Total Cost field, and return to the first step of the wizard.

Step 4: Add a Battle Station field (Master-Detail Relationship)

Just like resources, with supplies we need to relate them to a specific Battle Station record using a master-detail relationship.

Create the Battle Station relationship field as follows:

  1. For Data Type, select Master-Detail Relationship, and click Next.

  2. Select Battle Station from the Related To picklist, and click Next.

    • Field Label: Should default to Battle Station
    • Field Name: Battle_Station
  3. Leave the defaults for the remaining fields, and click Next.

  4. Click Next again to accept the default field visibility and security settings.

  5. Click Next to add the Battle Station field to the page layout.

  6. Click Save to add the Battle Station field to the page layout, the related list of Battle Station records to the page layout and save the Battle Station field, and return to the Supply Custom Object page.

Whew! That was a lot of work but we're finally done. Fortunately, that was the most time consuming part of building our application.

Resources

retargeting