Adding Fields to Your Object

,

The page shown in the figure above looks pretty bare, as there are no records within this object. Even if you click New, you only bring up the page shown in the following figure, where there admittedly is not much going on.

Figure 22. Adding a new location (first version)


You have to add some fields to the object to make the object more useful.

1.
Click Setup Create Objects to display the Location object in the object list.

There are three ways you can get to the Location object from this page. The Edit link takes you to a page to edit the values you entered in the last section, except for the inclusion of the Notes and Attachments option. You can still add the Notes and Attachments section to a tab page after creation, but you have to do it through the Page Layout, as you will see shortly.

The Del link deletes the object, after confirmation from you. When you delete an object, you also delete the associated data. By default, deleted objects and their data are kept for 45 days, during which time you can either restore them or erase them permanently from the Force Platform. The link for the name of the object takes you to a page where you can specify most of the attributes for the object, as you will see in the next step.

Clicking on the name of the object takes you to the page you will use most often in your development efforts.

Voice of the Developer

When editing custom objects, there are two types of pages you will need to access. The first page provides access to top level attributes that define the name and description of the object, and also control use of platform behavior such as Workflow and Reports. The second page is the one you will most likely be visiting more often, as it provides a means to add and edit new fields and layouts.

Clicking on the name of the object takes you to the second page, while the second first is accessible through the Edit link. You should train yourself to use this object name link to improve your development productivity and avoid the cursing that accompanies repeated frustration at the appearance of the first page.

2.
Click the Location link to display the page shown below.

This page includes a large number of attributes for your object. You will learn about all of them over the course of the next few chapters, but for right now, only the first three require descriptions:

  • Custom Object Definition Detail – includes all the information you entered when you defined the object. You can edit that information by clicking Edit.

  • Standard Fields – lists the fields that are included by default for this object. The fields are used to track the owner of the record, as well as information about the creation of the record and last modification of the record. The Record Name is the only one of the standard fields that you can edit.

  • Custom Fields & Relationships – the focus of the rest of this section



Figure 23. Detail page for the Location object


3.
Click New in the Custom Fields & Relationships section to display the page whose upper section is shown in the following figure.

This first page of the field definition process is used to select the data type for your new field. The page is divided up into three basic sections:

  • Read only data types - where the Force Platform system automatically generates the value. These data types include the Auto Number type you already encountered on the object definition page, a Formula field for displaying information derived from other sources, and a Roll-Up Summary Field, which is currently not enabled since the Location object does not include the prerequisites for the use of a Roll-Up Summary Field. You will define a Roll-Up Summary Field in the next chapter, and several formula fields in Chapter 4: Expanding data options. All of these data types produce a read-only field on the detail page for the object.

  • Relationship data types - defines two different types of relationships between the current object and another object. These data types establish the same type of relationship you define with a foreign key in a relational database. Relationships are the main focus of Chapter 3: Relationships.

  • Standard datatypes - used for the fields you will define in this section.

These data types both control the type of data allowed in the field, and, in some cases, the formatting of the user interface for the field in a tab. You have already created the Location Name field for this object as part of the object definition process. The first additional field you will define is the Address field.

Figure 24. Defining a custom field’s data type


4.
Select Text Area (Long) and click Next to bring up the page shown below.



Figure 25. Defining a custom field’s attributes


5.
Enter Street Address for the Field Label, limit the Length of the field to 2,000 characters, and set the number of visible lines as 4.

You can see that when you enter a Field Label, the Field Name is automatically defaulted to the label, with underscores in the place of spaces. As you will see, the actual name of the field, like the name of the object, is the name listed on this page followed by two underscores and the letter ‘c’ (__c).

Voice of the Developer

When adding fields, the Field Name is defaults to the Field Label by replacing spaces with underscore characters. Since the Field Name is the identifier you will later use in your Apex code it is worth considering your coding conventions at this point. If you have a Java or .Net background, you might prefer to see and use mixed case identifiers, such as newCandidate.CurrentEmployer__c vs newCandidate,Current_Employer__c in your Apex code. You can achieve this result, but only by changing the default Field Name.

6.
Enter a description for the field and some help text for this field.

7.
Click Next.

The next page gives you the ability to impose field level security restrictions on your new field. You will learn about security in Chapter 7: Protecting Your Data of this book, so you can accept the defaults on this page.

8.
Click Next to bring up the page shown below.

This page provides a recap of the most important attributes you have defined for your new field, as well as the ability to include this field in a Page Layout for its object.

Figure 26. Custom field attributes and inclusion on page layouts


9.
You will modify the Page Layout later in this chapter, so for now you can click Save and New to accept the default of adding the field to the page layout and complete the creation of this field and define another field.

This action takes you back to the Data Type page for your next field.

10.
Define the rest of the fields for the Location object with the attributes specified in the table below, accepting the default security and page layout options for each.

Table 1. Additional data fields for Location custom objects
Data TypeField LabelLengthRequired
TextCity50Yes
TextState/Province3Yes
TextPostal Code11No
TextCountry20Yes
PhonePhoneN/ANo
URLLocation MapN/ANo

As you define these additional fields, you will see that the detail options differ based on the data type you have specified for each field. For example, there are three checkboxes available for the Text fields you define, which allow you to specify that the value for the field is required, or that the value must be unique. These two attributes would not really make sense for a Text Area, which is typically used to hold optional data. Similarly, you are not prompted to enter a length for a field with a data type of Phone. This special data type automatically formats phone numbers entered by the user. The checkbox for an External ID will become more meaningful when you learn about relationships in Chapter 3: Relationships.

11.
When you have completed defining the last field, click Save to return you to the object page for the Location Object, as shown below.

Figure 27. Completed Location custom object


The fields you have just entered are listed in the Custom Fields and Relationships section of the Location object detail page in alphabetical order.

..................Content has been hidden....................

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