You are on page 1of 9

Tutorial 2: Create an App with the Force.

com IDE
Level: Intermediate
2030 minutes

The IDE is a toolkit extension to Eclipse that helps developers and development teams build, deploy, and track versions of components, including custom objects and fields, Apex classes, and Visualforce pages. In this tutorial, you will build the same Mileage Tracker application created in Tutorial 1 using both the IDE and the Builder tool. You will learn how to change the metadata that describes the structure of an application by manipulating XML descriptors in the IDE. You can change the metadata much more quickly in the IDE than by using the Builder, especially when doing bulk operations such as migrating schemas from another database to or cloning a instance.

This tutorial consists of six steps; please proceed through them in sequence.
Step 1: Create a project Step 2: Create the Mileage record custom object Step 3: Create custom fields Step 4: Create a tab Step 5: Create an application Step 6: Test the application

For this tutorial, it helps to have basic knowledge of XML, but it is not required.

Software Requirements
Eclipse 3.3 IDE for Eclipse

Note: The Tour de Force lab computers already have these tools installed.

Getting started
If you have already created the Mileage Tracker application in your Developer Edition org account by completing Tutorial 1 or Tutorial 5, you must first delete all the objects you createdincluding the custom object, the tab, and the applicationso that the existing names dont conflict with those in this tutorial.

Step 1: Create a project

1. 2. 3. 4. Launch the Eclipse environment. In the Tour de Force labs, there is a shortcut on the desktop. Click File > New > Project from the Eclipse main menu. In the wizard, expand the group. Select Project and click Next.

5. Specify your Developer Edition org credentials: a) Enter a name for you new project. b) Enter your Developer Edition username. c) Enter your Developer Edition password. d) Accept the remaining defaults. e) Click Finish. You have just created a project!

Note: If you get a LOGIN_MUST_USE_SECURITY_TOKEN error, it means your current IP is not recognized from a trusted network range. Follow the instructions in the error message to generate or reset a security token.

Step 2: Create the Mileage record custom object

In, an object is similar to a database table: a list of information, organized in records and fields, about the person, thing, or concept you want to track. Each object automatically generates a user interface through a tab and offers built-in features such as a user interface, a security and sharing model, workflow processes, and much more. 1. Create the custom object. a) In the IDE, right-click (Ctrl-click on a Mac) on your projects folder and select New > Custom Object.

b) Under Custom Object Properties, enter Mileage in the Name field. c) Tab out of the field and click Finish. d) Expand the src > unpackaged > objects section in the Package Explorer. You should now see a custom object named Mileage__c.object in the Objects folder. This is the object you just created. This file is open in the editor as well. e) Switch to the Source view (at the bottom of the Mileage__c.object editor). f) Change the label of the nameField in the Mileage__c.object file from Custom Object Label Name to Mileage Report Number. This field will be used to identify the record in the Mileage object. The XML file in the IDE should now look like this:
<?xml version="1.0" encoding="UTF-8"?> <CustomObject xmlns=""> ... <nameField> <label>Mileage Report Number</label> <type>Text</type> </nameField> ...

g) Click on the Save icon in the top menu to save the file. 3

You have created a project and a custom object in the client-side IDE. 2. Verify that the object exists in your instance. a) Right-click (Ctrl-click on a Mac) on the Mileage__c.object in the Package Explorer.

b) Choose > Show in Salesforce Web to log in and display the Builder page for the custom object in the browser. c) You should now see the page describing the Mileage__c custom object in the Builder in the browser. 3. Auto-number the records. a) In the Standard Fields section of the Builder page, you can see the field labeled Mileage Report Number that you specified earlier. You can change the characteristics of this field so the user doesnt have to specify a name every time a Mileage record is created. b) Click the Edit link next to the Mileage Report Number field. Change the Data Type to Auto-Number. Specify the display format to be MR-{0000}. Specify the starting number to be 1. 4

c) Click Save. d) Go back to the IDE browser window, right-click (Ctrl-click on a Mac) on the Mileage__c.object, and choose > Refresh from Server. e) Click Yes to confirm the refresh. You should now see a new element under nameField displayFormat. The value of Type changed from Text to AutoNumber.

Step 3: Create custom fields

Now that you have created the Mileage object, youll want to add fields to capture the date of the record, the number of miles driven, and the person visited. 1. Create the first custom field with the Builder. a) Return to the Builder page in the browser. b) In the Custom Fields & Relationships area of the Mileage custom object, click New to launch the Field Creation wizard.

c) In Step 1 of the wizard, select Date as the Data Type and click Next. This field will be used to store the date of the mileage report. d) In Step 2, enter the following values: Field Label: Date Field Name: Date Description: Date of mileage report Required: Checked Default value: TODAY() e) Click Next. f) In Step 3, accept the field-level security defaults and click Next. g) In Step 4, accept the default (to add the field to the page layout) and click Save. You have just created a new custom field for your custom object, made it accessible to all user profiles, and automatically added it to the page layout. 2. Create the remaining fields with the IDE. You now need to create a few more fields, but rather than use the Builder, you can use the IDE. a) Return to the IDE and right-click (Ctrl-click on a Mac) on the Mileage__c.object. b) Select > Refresh from Server to update the IDE environment with the changes from the server. c) Click Yes to confirm the refresh. You will see the entry for the Date field that you added in the previous step. 5

d) Add two additional fields: Contact and Miles. 3. In the Mileage__c.object, insert the text shown in bold. Youll notice that as soon as you start typing, the IDE supports code-completion when editing XML descriptors.
<?xml version="1.0" encoding="UTF-8"?> <CustomObject xmlns=""> <deploymentStatus>Deployed</deploymentStatus> <description> This is a generic template for CustomObject. With this template, you may adjust the default elements and values and add new elements and values. </description> <fields> <fullName>Date__c</fullName> <description>Date of Mileage Report</description> <label>Date</label> <required>true</required> <type>Date</type> </fields> <fields> <fullName>Contact__c</fullName> <label>Contact</label> <referenceTo>Contact</referenceTo> <relationshipName>Mileages</relationshipName> <type>Lookup</type> </fields> <fields> <fullName>Miles__c</fullName> <label>Miles</label> <precision>4</precision> <required>true</required> <scale>0</scale> <type>Number</type> </fields> <label>Mileage</label> <nameField> <displayFormat>MR-{0000}</displayFormat> <label>Mileage Report Number</label> <type>AutoNumber</type> </nameField> <pluralLabel>Mileages</pluralLabel> <sharingModel>ReadWrite</sharingModel> </CustomObject>

4. Click Save to automatically save the changes to your organization. 5. Verify the fields in the Builder and add them to the page layout. a) Refresh the Builder page in the browser. You should see the Contact and Miles fields in the Custom Fields & Relationships area, along with the Date field you created earlier. b) In the Page Layouts section, click the Edit button next to Mileage Layout. c) Drag and drop the Contact field (on the bottom right of the page) into the Information box. Note that the Miles field was automatically added to the page layout because you specified it is required in the XML. d) Click Save.

Step 4: Create a tab

In this step, you will create a tab that exposes the Mileage custom object to the user through a tab at the top of the runtime environment. The tab will display the most recently 6

accessed items for the object as well as the buttons to bring up pages for creating new Mileage records or editing existing records. 1. In the left panel of the Builder menu, select App Setup > Create, and click Tabs. 2. Click New at the top of the Tabs list to launch the New Custom Tab wizard.

3. Enter the following values: Object: Mileage Tab Style: Car 4. Click Next. 5. In Step 2, accept the defaults and click Next. 6. In Step 3, accept the defaults and click Save. You should now see a Mileages tab as part of your tabset. 7. In the IDE Package Explorer, right-click (Ctrl-click on a Mac) the src folder and choose > Refresh from Server. You should now see a tabs folder under the unpackaged folder.

Step 5: Create an application

Applications can combine several tabs and include other components, such as dashboards and reports. In this step, you will create an application containing the Mileage custom object and the Contact standard object. 1. Create the Application in the IDE. a) In the IDE, right-click (Ctrl-click on a Mac) on your project folder and select New > Custom Application.

b) Enter the name Mileage Tracker. c) Tab out of the field and click Finish. d) Edit the Mileage by inserting the text shown in bold:
<?xml version="1.0" encoding="UTF-8"?> <CustomApplicationxmlns=""> <description>A description</description> <tab>Mileage__c</tab> <tab>Contact</tab> </CustomApplication>

e) Click Save. Saving the new custom application to the server automatically updates your organizations profiles. 2. Configure user profiles A profile is a collection of settings and permissions that determine what a user can see or do on the platform. To allow the default profile (Admin) to see the new application, you must make it visible to the Admin profile. a) To bring the updated profiles back to the IDE, go to the src > unpackaged > profiles folder in the IDE package explorer, right-click (Ctrl-click on a Mac) on the src folder and choose > Refresh from Server. b) In the src > unpackaged > profiles folder, double-click the Admin.profile file to open it. c) Change the value of the Visible element for Mileage Tracker to true, as illustrated in the bold text:
<?xml version="1.0" encoding="UTF-8"?> <Profile xmlns=""> <applicationVisibilities> <application>Mileage Tracker</application> <default>false</default> <visible>true</visible> </applicationVisibilities> ... </Profile>

d) Click Save. e) Go back to the Builder window and refresh. You should now see an application called Mileage Tracker in the Application dropdown list at the top right of the page.

You can now test the applications functionality by creating a new record. 8

Step 5: Test the Application

1. Select the Mileage Tracker application from the Application dropdown list. 2. Click the Mileages tab and click New to create a new record. 3. Enter some test data (use Tim Barr as the Contact) and save the record. Keep the miles under 500 because you will create logic in Tutorial 3 to enforce total daily mileage limits of less than 500 miles.

In Tutorial 1 and Tutorial 2, you created the basic Mileage Tracker application with both the IDE and the Builder. In this tutorial, you learned the following: A project in the IDE gives you access to the metadata of a Salesforce organization. You can use the IDE to create, modify, and delete metadata components. You can make changes in either the IDE or in the Builder and then synchronize the changes in either direction.