We have successfully created the Customer object. We are going to take a look at some major types of custom fields on Force.com. Let's create the fields for the Customer object.
When we create a new field, we have to go through four steps. Let's take a look at each one of them in detail.
Custom objects include some standard fields that are included automatically. When we create a new custom object, it automatically has five standard fields. To capture additional data in the object, we need to add more fields to it. The standard fields include audit fields such as:
Apart from the owner field, the other fields cannot be edited from the UI. The owner field is automatically assigned to the person who created the record and can be changed by transferring the record to another user.
The Force.com platform provides us with some good and unconventional custom data types. These custom data types are directly aligned with business use cases and come packed with unique properties and validation rules. For example, the Email
field comes automatically with e-mail validation, the URL
field automatically checks whether the input is a valid URL, the Phone
field automatically formats the phone number in the local format. One of the latest additions to the custom fields is geolocation compound fields
that come bundled with functions to calculate the distance between two locations.
We can change the data type of a custom field in some cases; however, it is not recommended as it can result in data loss. For example, we can change a text area to a text field; this may result in loss of data (truncate) if the field length is also decreased.
To begin with, let's create a few custom fields and take a look at the custom field wizard.
The first step to create custom fields is to choose the right field type that can capture the correct data.
Let's take a detailed look at all the custom field types.
Text fields are used to capture free-flowing text. They are used to capture alphanumeric data. The five types of text fields are used to capture different lengths of data:
There are four types of basic text fields, which are as follows:
Picklist is a type of predefined text field. It can be used to prevent spelling mistakes and grammatical errors while entering the data. Picklist is rendered as a drop-down select list on the UI, but it is stored as text in the database. It can store predetermined values, such as City names
, State names
, and Status
:
Picklist (Multi-select) is a special type of picklist that can allow the users to select multiple values at the same time.
Let's take a look at the other general data fields:
Checkbox: This field stores values as true or false. On the page layout or Visualforce, the field is rendered as a checked box for true and an unchecked box for false.
Date: This field captures the date based on a data picker. The Salesforce platform stores the date/time values in the GMT time zone, but the values that are displayed are based on the Locale & Time Zone preferences in My Settings:
Date/Time: This is similar to the date but also captures the time along with the date.
Email: This captures and validates the e-mail values.
Number: This field is used to capture numeric values. We can specify the number of digits before and after the decimal point.
Percent: This field captures the percent data. The values are stored as decimals, such as 0=0%, 0.5=50%, 1=100%, and so on.
Phone: When we enter the phone number through the Salesforce UI, it is auto-formatted as Phone. If we use a third-party softphone with Salesforce, the phone number fields are auto click-to-dial-enabled.
URL: This captures the URL and makes it a clickable link.
Geolocation is a compound field that allows us to identify the location using the latitude and longitude. The geolocation field comprises three separate fields: latitude, longitude, and a field used for internal purposes. The Geolocation field comes bundled with special formulas, such as DISTANCE
that calculates the distance between two geolocation fields:
The geolocation field is broken down into separate latitude and longitude components demarked by __s;
for example, if the field is called Location
, then the latitude is stored as myObject__c.Location__latitude__s
and Longitude is stored as myObject__c.Location__Longitude__s
.
The Currency field captures the currency values, such as Price
and Amount
. If your organization has multi-currency enabled, another field called CurrencyIsoCode
is visible that allows you to select the type of currency. When multi-currency is enabled, the currency field converts the value into corporate currency and displays it on the field:
We can specify the exchange rate in the setup. We can also specify historic exchange rates for existing values.
Currency fields are easy to export into Excel as they are directly compatible with the Excel currency format.
Let's take a look at the encrypted fields:
If the Salesforce org is storing some sensitive information, such as credit card numbers, social security numbers, bank account numbers, and so on, we can use the encrypted field access to the Salesforce org.
The encrypted fields mask the value of the information with an *. For example, ****-****-****-1234 for a credit card field, as shown in the following screenshot:
We can choose the mask type of the encrypted field, as shown in the following screenshot:
Encrypted fields are used to mask the value of the field from users. The only way to see the encrypted fields is by enabling the View Encrypted Data permission on the profile.
Encrypted fields cannot have default values and cannot be unique or external IDs.
The encrypted field can be edited irrespective of the View Encrypted Data permission. To prevent people from editing them, we need to use the field level security, validation rules, or mark them as read only on the page layout.
Encrypted fields are encrypted with 128-bit keys and use the AES (Advanced Encryption Standard) algorithm. They are 175 characters in length, unlike the normal text field, which is 255 characters.
Due to encryption, there are some limitations on the use of encrypted fields:
Since Summer 2015, Salesforce has offered another level of encryption known as the platform encryption. When we enable the platform encryption, a few standard fields and some custom fields can be encrypted.
The following fields can be encrypted using the platform encryption:
Account Name
Fax
Home Phone
Mailing Address (encrypts only Mailing Street and Mailing City)
Mobile
Name (encrypts First Name, Middle Name, and Last Name)
Other Phone
Phone
Subject
Description
Body
Custom Fields:
Phone
Text
Text Area
Text Area (Long)
URL
Only users with View Encrypted Field can see the data. For more information on the platform encryption, go to https://help.salesforce.com/HTViewHelpDoc?id=security_pe_overview.htm.
A formula field is a special type of field that uses a formula similar to an Excel formula. It is calculated at runtime and uses functions, operators, and other fields to calculate its value.
Here's an example of a formula field on a media object. It calculates the number of days after the due date has expired (assuming that we have all the fields in the media object):
If(TODAY()>BookIssueDate__c,TODAY() - BookIssueDate__c,0);
The members of the general library are allowed to borrow the media items for only 15 days. They want to reduce the typing work for the entry clerk and wish to auto-calculate the return date of the book.
The return date will be calculated on the CustomerMedia object that will record the transaction when the book is issued. To create the Return Date formula:
Issue_Date__c +15
formula to the formula editor, as shown in the following screenshot:Issue_Date__c+15
is the date field used to store the issue date for the media. We can also use the Insert
field's drop-down list to insert this field. Make sure that you click on the Check Syntax button to compile the formula and check for errors.Every time a new record is created with the Issue Date, the Return Date field will automatically calculate and store the return date for it.
Using cross-object formula fields, we can calculate the value of a field based on fields in the parent record. We can traverse up to five levels upwards from the parent relationship.
The record owner and activity fields cannot be used in cross-object formula fields. Let's create the cross-object formula field for the Customer object.
A general library wishes to calculate the Penalty Amount for a media resource when it is checked out late. Write a formula field that can calculate the amount for the Customer–Media object.
The formula field is a read-only type of field that is auto-calculated. We define the formula on the basis of other fields and static values and the formulae are auto-calculated globally on the page.
Let's create a formula
field to calculate the penalty. Select the Formula field in the list of fields. It will open the Formula creation wizard:
The formula quick reference guide on Force.com provides an effective cheat sheet for the formulae. You can refer to it at https://na3.salesforce.com/help/doc/en/salesforce_formulas_cheatsheet.pdf.
Return_date__c
, which we created in the previous section. Create the (TODAY() - Return_date__c )* Media__r.Loss_Fine__c
formula to calculate the fine, as shown in the following screenshot:We have already discussed that Force.com is an object-oriented relational database management system. The backbone of the entire system based on Force.com is relationships.
Relationship fields determine how an object is related to another. For example, a library user will have a library card that can issue many books; an Account can have many opportunities. We can create these relationships using the relationship fields.
There are two main types of relationship fields, as shown in the following screenshot:
Let's take a look at each one of them.
The lookup relationship is the most basic form of a relationship. The lookup relationship is a foreign key on another object. While creating a lookup relationship, we can determine the behavior of the related record if the primary record is deleted.
If the primary record is deleted, then we need to choose from the following options:
The Lookup relationship can be visualized in the following figure:
For example, a card of a member can have multiple penalties (fines) on it. The penalties on the card are shown at the bottom of the card in a list.
Lookup relationships have the following properties:
The following figure illustrates the Master-Detail relationship:
Master-Detail relationships are more tightly coupled relationships. One object is the Master or Primary object and the other is the Detail or Secondary object. The primary object controls the look and style of the tab as well as the security of both the objects. When the primary record is deleted, the secondary record is deleted as well.
For example, the relationship between the customer and the card in the library management will be Master-Detail where the customer is the master and the card is the child in the relationship.
Master-Detail relationships have the following properties:
We cannot create a Master-Detail relationship in an object that contains records in detailed objects. If there are records present in the detailed object, the trick is to create a lookup relationship first. Populate the lookup fields on the existing records and then change them to master-detail.
The roll-up summary field is a special type of field that can be used in a master-child relationship. Roll-up summary fields are used to aggregate the numeric fields from the Child object on the master object. The roll-up summary field uses aggregate functions, such as SUM
, MIN
, MAX
, and COUNT
. They are calculated periodically and their value is stored in the database.
A general library wishes to keep track of all the media items issued to the customer. They want the total number of items issued in a single field called Media Issued against the member record.
The media items that are issued against the customer are stored in the CustomerMedia object; we will store their count in the Customer object:
This covers the basic formulae and the logic that helps us simplify our work.
In the following section, we will discuss how to automate business processes using workflows and approval processes.
Using Master-Detail and Lookup relationships, we can create two more types of relationships:
A real-world example is the relationship between a student and teacher. A student can be taught by multiple teachers while a teacher can teach multiple students. We can create a many-to-many relationship between two objects by creating a third object that has both the main objects as a primary relationship.
The third object thus created is called a Junction object. It is a junction between the two objects.
Some properties of the junction objects are as follows:
When we select the desired field types in the previous step, the second step allows us to customize the field and its properties. The following are the most common attributes in the text fields, as shown in the following screenshot:
A universally Required field is a custom field whose value is always required whenever a record is saved in Salesforce, the Force.com API, Connect Offline, Connect for Lotus Notes, Connect for Outlook, Salesforce for Outlook, the Self-Service portal, or processes such as Web-to-Lead and Web-to-Case.
To create a universally required custom field, check Always require a value in this field in order to save a record option.
If there is a need to make a particular field required for a particular record type, do not make it universally required. The field can be set as required from the page layout of the record type. We will discuss how to make a field required in the next chapter. Refer to the page layout section in Chapter 3, User Interface for more details.
The following fields can be made universally required:
The custom field can be made unique and case-sensitive using this option. Unique fields will automatically get the duplicate check attach while inserting values in them.
To set a field as unique, select the Set this field as the unique record identifier from an external system checkbox, as shown in the previous screenshot.
External ID is a user-defined cross-application reference field. If the company is using some legacy system or any other computer system to store data, which is to be synced with Salesforce.com, the primary key in the external system is marked as an external ID in Salesforce.
The benefits of an external ID are as follows:
The third step to create the field is to set up the Field-level security. Whenever we create a new field, we need to determine who can edit it and who can only read it. This step is required for every new field as improper field-level security could prove hazardous for data-security.
In the third step, we choose on which profile the field is Visible and on which profile the field is Read-only. We can customize the field-level security of each individual profile, and hence we will revisit this part again when we discuss the profile-based security.
The general library collects different information about books and videos. Create different fields (as required) to catalog the information.
To create a field on the object, perform the following steps:
A dependent picklist is a picklist whose values are filtered by another controlling picklist. The values in a dependent picklist are changed according to the values selected in the controlling picklist. Standard picklists are always controlling fields. Custom picklists can be dependent as well as controlling.
The general library wishes to create categories and subcategories of books that are available. They first classify the books according to the fiction and nonfiction categories. Fiction books are further classified as children's fiction, fantasy, thriller, and comedy. Nonfiction books are then classified as self-help, management, spiritual, biographies, and inspirational.
We will create the picklist on the Media__c
object that we created in our previous exercise.
To create a dependent picklist, we first need to create two normal picklists. First, create a general picklist of the fiction and nonfiction categories, as shown in the following screenshot:
We create another picklist that has all the combined values of fiction and nonfiction, as shown in the following screenshot:
The steps to create a dependent picklist are as follows:
On the page layout, you will see that the Sub Categories checkbox is disabled until you select the categories.
Validation rules are used to preserve the data quality. We can use validation rules to prevent the data loss from the record. They are executed before the record is committed to the database. A validation rule is executed irrespective of whether the record is saved from the UI or from the API. If the evaluation of the error condition results in a true value, the record is not saved and an error message is generated.
Some standard fields have built-in validation. For example, an E-mail field checks for a valid e-mail, while the Number field checks for numbers entered in the string. For all other custom validations, we can use validation rules.
Let's take an example to check whether the discount given to a customer is not greater than 10%. For this example, we will use a percent field called DISCOUNT on the Customer_Fine
object.
We can use the isChange
formula to determine whether the value in a certain field is changed and the user profile.
Our general library wishes to reinforce the rule on the number of books a user can check out. Every user will have a limited number of books they can issue, depending on their membership type. We will store Total_media_allowed__c
in a Number field. Total_Media_Issued__c
is a roll-up summary field that stores the number of Media issued to the customer.
To create a validation rule, perform the following steps:
The formula uses basic functions, which are provided by Salesforce.com. These functions are similar to the Excel-based functions. For a complete list of functions, visit the formula quick reference guide at https://na3.salesforce.com/help/doc/en/salesforce_formulas_cheatsheet.pdf.
$User.City
.ObjectType
.3.131.142.80