Académique Documents
Professionnel Documents
Culture Documents
com IDE
Level: Intermediate
2030 minutes
Overview
The Force.com IDE is a toolkit extension to Eclipse that helps developers and development teams build, deploy, and track versions of Force.com 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 Force.com IDE and the Force.com Builder tool. You will learn how to change the metadata that describes the structure of an application by manipulating XML descriptors in the Force.com IDE. You can change the metadata much more quickly in the IDE than by using the Force.com Builder, especially when doing bulk operations such as migrating schemas from another database to Force.com or cloning a Force.com instance.
This tutorial consists of six steps; please proceed through them in sequence.
Step 1: Create a Force.com 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
Prerequisites
For this tutorial, it helps to have basic knowledge of XML, but it is not required.
http://developer.force.com
Software Requirements
Eclipse 3.3 Force.com 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.
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 Force.com project!
http://developer.force.com
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.
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 Force.com IDE should now look like this:
<?xml version="1.0" encoding="UTF-8"?> <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> ... <nameField> <label>Mileage Report Number</label> <type>Text</type> </nameField> ...
g) Click on the Save icon in the top menu to save the file. http://developer.force.com 3
You have created a Force.com project and a custom object in the client-side Force.com IDE. 2. Verify that the object exists in your Force.com instance. a) Right-click (Ctrl-click on a Mac) on the Mileage__c.object in the Package Explorer.
b) Choose Force.com > Show in Salesforce Web to log in and display the Force.com Builder page for the custom object in the browser. c) You should now see the page describing the Mileage__c custom object in the Force.com 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. http://developer.force.com 4
c) Click Save. d) Go back to the Force.com IDE browser window, right-click (Ctrl-click on a Mac) on the Mileage__c.object, and choose Force.com > 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.
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 Force.com IDE. You now need to create a few more fields, but rather than use the Force.com Builder, you can use the Force.com IDE. a) Return to the Force.com IDE and right-click (Ctrl-click on a Mac) on the Mileage__c.object. b) Select Force.com > Refresh from Server to update the IDE environment with the changes from the Force.com server. c) Click Yes to confirm the refresh. You will see the entry for the Date field that you added in the previous step. http://developer.force.com 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 Force.com IDE supports code-completion when editing XML descriptors.
<?xml version="1.0" encoding="UTF-8"?> <CustomObject xmlns="http://soap.sforce.com/2006/04/metadata"> <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 Force.com organization. 5. Verify the fields in the Force.com Builder and add them to the page layout. a) Refresh the Force.com 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.
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 Force.com 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 Force.com IDE Package Explorer, right-click (Ctrl-click on a Mac) the src folder and choose Force.com > Refresh from Server. You should now see a tabs folder under the unpackaged folder.
http://developer.force.com
b) Enter the name Mileage Tracker. c) Tab out of the field and click Finish. d) Edit the Mileage Tracker.app by inserting the text shown in bold:
<?xml version="1.0" encoding="UTF-8"?> <CustomApplicationxmlns="http://soap.sforce.com/2006/04/metadata"> <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 Force.com 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 Force.com IDE package explorer, right-click (Ctrl-click on a Mac) on the src folder and choose Force.com > 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="http://soap.sforce.com/2006/04/metadata"> <applicationVisibilities> <application>Mileage Tracker</application> <default>false</default> <visible>true</visible> </applicationVisibilities> ... </Profile>
d) Click Save. e) Go back to the Force.com 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. http://developer.force.com 8
Summary
In Tutorial 1 and Tutorial 2, you created the basic Mileage Tracker application with both the Force.com IDE and the Force.com Builder. In this tutorial, you learned the following: A Force.com project in the Force.com IDE gives you access to the metadata of a Salesforce organization. You can use the Force.com IDE to create, modify, and delete metadata components. You can make changes in either the Force.com IDE or in the Force.com Builder and then synchronize the changes in either direction.
http://developer.force.com