Chapter 2. Creating a Database on Force.com

Now that we have defined the types of applications that can be built with Force.com and created a developer account, we can move deeper into application development. In this chapter, we are going to:

  • Create objects
  • Create fields
  • Create relationships

The exercises covered in this chapter will be useful for you till the time you are working on the Force.com platform.

So, let's begin.

Objects

Force.com is an object-oriented relational database system. An object is the background of any application built on Force.com. An object is like a database table that allows you to store data in different formats. It also gives you options to create a UI in order to enter, modify, or delete records.

Force.com doesn't give you the option to create database tables using code. To create a table, we need to define the object using the UI. The UI not only allows you to define the object definition but also comes with unique built-in features, including recording activities (such as logging a call, sending an e-mail, and so on) and the ability to add notes and attachments. The platform automatically creates a standard UI for the object thus defined and adds basic features, such as create, update, and delete.

Tip

Note

An object in Salesforce is like a worksheet in Excel or a table in the database. A field in an object is similar to a column in an Excel sheet or a table, and the record of the object is similar to a row in an Excel sheet or a database.

Before we define a new object, let's explore what Force.com offers us initially.

Standard objects

Standard objects are part of Salesforce CRM Cloud. These objects are offered as is, and while we can extend them and add new attributes to them, we cannot modify the existing attributes unless permitted; for example, while we can add new values to Status Picklist, we cannot change the name of the Picklist value.

The following are important objects that are part of the Sales Cloud:

  • Accounts: The entire CRM Universe revolves around Accounts (and Contacts). An individual account is an organization that is associated with your business. It could be your Customer, Competitor, or Partner.
  • Contacts: A contact complements an Account by acting as a contact manager or an address book.
  • Leads: A lead is the contact information for a prospect or an opportunity.
  • Opportunity: An opportunity is a pending sale or a deal.
  • Other supporting Objects: Along with the top four objects mentioned previously, there are many other supporting objects, such as Products, Orders, and so on.

The following are objects from the Service Cloud offering:

  • Case: This is a customer issue such as a customer's feedback, problem, or question.
  • Solutions: These store the detailed description of a customer's issue and the resolution of that issue. These objects and others come with the packaged CRM offering. Along with them, we have built-in processes, for example, Leads can be converted into Contacts and Accounts. We can create Case from Email. We can rename the standard objects based on the business process; for example, we can rename Accounts to Customers and Leads to Prospects. The other ways to customize the standard application is to extend it by adding custom fields or modifying the Picklist values.

Custom objects

Apart from the standard objects defined earlier and others that come built-in with the Salesforce CRM package, we can extend the Force.com platform by building our own set of custom objects.

Let's explore custom objects in detail.

Exercise – creating your first custom object

The public library needs to store information regarding its customers, its workers, the physical locations of its branches, and the media stored in those locations.

It specializes in lending out two types of media: books and videos. The library must keep track of the attributes of each media item, its location, status, descriptive attributes, and cost for losses and late returns.

Books will be identified by their ISBN and videos by their title and year. In order to allow multiple copies of the same book or video, each media item will have a unique ID number.

The following diagram shows a basic E-R diagram of the Library Management System:

Exercise – creating your first custom object

The Library Management System

The library customers will provide their name, address, phone number, and date of birth when signing up for a library card. They will then be assigned a unique ID number. Checkout operations will require a UID number as well as requests to put media on hold. Each library card will store its own dues. The late fees for returning the media items will be stored in a separate penalty object. These penalties will be summed up for the master object.

Employees will work at a specific branch of the library. They receive a paycheck, but they can also have library cards; therefore, the same information that is collected from the customers should be collected from the employees as well.

The object structure of the Library Management can be summarized in the following table:

Object name

Related to (Relationship)

Comments

Media

CustomerMedia (Detail object of Media)

The media object is the master table used to store the collection of media. Books and videos are separated by the record type to show different types of media.

Customer

CustomerMedia (Detail Object of Customer)

Book Penalty (Detail object of Member)

The Customer object stores the customer information. It also stores the total fine paid by the customer as a roll-up field.

CustomerMedia

Customer, Media (Master Object)

The CustomerMedia object stores the customer and media in a junction object and is used during the checkout and checkin function of the Library Management System.

Book Penalty

Customer

This is a child object of the Customer object and stores the amount of late fees paid by the customer.

The Library Management System

For the purpose of this exercise, we need to create all the four objects for the Library Management System, so let's start with the Customer object.

The steps to create a custom object are as follows:

  1. Go to Setup | Build | Create | Objects.
  2. Click on the New custom object.
  3. Enter the details in the object. The following screenshot shows the Custom Object wizard:
    Exercise – creating your first custom object

    The wizard consists of the following fields:

    Field

    Description

    Label

    The label of the object is seen on the user interface. This will be used everywhere on reports, UI pages, and records. For example, Customer and Media.

    Plural label

    This is used when we are creating the tab of the object. For Example, Customers and Media.

    Starts with a vowel sound

    This checks whether the label should be preceded by an instead of a.

    Object name

    This is a unique name used to refer to the object when using the Force.com API; hence it is also called the API name. The label is seen on the frontend and the UI of the application while the API name is used to refer to the object from the backend.

    The Object Name field can contain only underscores and alphanumeric characters. It must be unique, begin with a letter, not include spaces, not end with an underscore, and must not contain two consecutive underscores. For example, customer.

    Note: Force.com automatically appends a __c (a double underscore c) to every object name. This is not seen in the UI form but is stored in the database with the name. This is how Force.com distinguishes between standard objects and custom objects. The API name of the Custom Account object becomes Custom_Account__c.

    Description

    An optional description of the object. The description saves us the trouble of remembering why we created the object in the first place when we are viewing the list of all the objects. This is extremely helpful when working with a team.

    Context-sensitive help setting

    If we are using a custom help system for applications built for customers, we select the custom help Visualforce page or S-control here.

    Record Name

    The record name used in page layouts, list views, related lists, and search results. For example, Customer Name, Customer Number, or UID.

    For the purpose of the example, we can name the record name UID.

    Note: Irrespective of what the record name is, the API name of the field is always name and is consistent across all standard and custom objects.

    Data Type

    This determines the type of field (text or auto number) for the record name. An auto number is a unique number assigned automatically. If the data type is an auto number, it is a read-only field.

    For the purpose of the exercise, we can create the data type as an auto number. This will be the UID of the media.

    Display Format

    For a Record Name of the auto number type, enter a display format. The display format can be of the following types:

    Format

    Displayed values

    {0}

    Incremental single-digit values, for example, 0, 2, 3, and so on.

    {000}

    Incremental three-digit values, for example, 000, 002, 003, and so on.

    Customer- {00000}

    Customer - 00003, Customer -123, and so on

    UID- {00} {MM} {DD} {YY}

    UID -02 011410, UID -123 071910

    Customer #{0} {MM}-{DD}-{YYYY}

    Customer #02 01-14-2010, Customer #123 07-19-2010

    Starting Number

    For a record name of the auto number type, this is the number from where the counting starts.

    Allow Reports

    This makes the data in the custom object records available for reporting purposes. We will discuss reports later in detail.

    Allow Activities

    This allows users to associate tasks and scheduled calendar events related to custom object records. The related lists of activities are directly added when this checkbox is enabled.

    Track Field History

    This checkbox helps you record the field changes made to the object, such as who changed the value of a field, when it was changed, and what the value of the field was before and after the edit. We can maintain a history of 20 fields for a maximum of 18 months. We can easily create audit trail reports when this feature is enabled.

    Note: Following the Spring 15 release, we can purchase the Field Audit Trail Add-on to track more than 20 fields.

    Deployment Status

    The custom object won't be visible to any users unless it is deployed. The best practice is to always create objects in Sandbox and deploy them in production, but if you need to develop in production then you can keep the object hidden by marking it as in-development.

    Add Notes & Attachments

    This allows users to attach notes and attachments to custom object records. This allows you to attach external documents to any object record, in the same way in which you can add a PDF or photo as an attachment to an e-mail.

    This option is only available when you are creating a new object. We can add or remove the Notes & Attachment-related list from the page layout.

    Launch the New Custom Tab Wizard

    Checking this option will launch the custom tab wizard for the object immediately. We will go through this wizard later in this chapter. For now, do not launch the custom tab wizard.

    We can at any time go to Setup | Build | Create | Tabs to create a new custom object tab.

    Fill the form with the values for the Customer object. Label the object as Customer; the plural is Customers. Fill the other values according to the description.

  4. Save the page.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.184.122