Deploying Code with the Force.com IDE. salesforce v35.0
Force.com IDE v35.0 is a powerful tool for developing applications on the Force.com platform using Apex, Visualforce, and metadata components. It includes features to accelerate Force.com application development, such as wizards, source code editors, test execution tools, deployment aids, integrated help, and an interactive debugger.
Advertisement
Advertisement
Getting Started with the Force.com IDE Deploying Code with the Force.com IDE
For more information, see “Understanding Testing in Apex” in the
Force.com Apex Code Developer's Guide.
SEE ALSO:
Debug Logs for Apex Test Results
Apex Code Settings: Log Category and Log Level
Troubleshooting the Force.com IDE: Debug Mode
Deploying Code with the Force.com IDE
Once you have created application components and tested them in your own development organization, you usually want to migrate them to a different organization for testing, staging, publication, or production use by end users.
Though each Force.com metadata component lives and runs in a particular organization on Force.com servers, the metadata files you work with in the Force.com IDE are portable from one organization to another. Deploying is the process of pushing your local project files into a different Salesforce organization than your project’s home organization. The Force.com IDE provides the Deploy to Server wizard to guide you through the deployment process.
Before you deploy, you can streamline your deployment process by creating a new project with only the components you want to
deploy. For information, see Create New Force.com Project .
Note:
If you deploy to a production organization, you must meet the Apex testing compliance policy: 75% of your Apex must be covered by unit tests, and all of those tests must complete successfully. Additionally, each trigger must have some code coverage.
To open the Deploy to Server wizard, right-click the src
folder of the project and select Force.com > Deploy to Server. You can also select individual classes or triggers, multiple classes and triggers, or the classes
or triggers
folder. Before the wizard opens, the
IDE checks for conflicts between the project and the home organization. If conflicts are found, you are given the option to synchronize before continuing.
The Deploy to Server wizard includes the following pages:
2. On the Archive Options page, optionally create backup files for this deployment and click Next.
page, review the actions to be performed in this deployment. Click Next to execute the deployment.
4. The Deployment Result page displays the result of the deployment. You should see Success displayed at the top of the page. If you do not, review the deployment logs by clicking View Logs. If you need assistance with deployment errors, click Save to save your log file for future reference.
SEE ALSO:
18
Getting Started with the Force.com IDE Quickstart: Using the Force.com IDE
Quickstart: Using the Force.com IDE
This simplified quickstart guides you step-by-step through the following tasks:
1. Create a new project.
2. Create an Apex class and trigger that populates the custom field with text.
3. Add a unit test to automatically test the method.
Note:
To complete this exercise, you must have administrative access to two different organizations: either two Developer Edition organizations, or a Developer Edition organization and a sandbox organization. Do not use a production organization for this exercise.
1. Create a Project
The following steps create an Eclipse project and connect it to the home organization (the organization associated with the project):
1. Select File > New > Force.com Project.
Note: If you do not see Force.com Project in the File > New menu, you are not using the Force.com perspective. You can still create a Force.com project without using the Force.com perspective by selecting File > New > Other > Force.com >
Force.com Project; however, you should use the Force.com perspective because it includes other views and features that aid development. To activate the Force.com perspective, select Window > Open Perspective > Other > Force.com
Perspective.
2. Enter the following information and click Next:
Field
Project Name
Username
Password
Security Token
Environment
Do not change endpoint
Timeout (sec)
Proxy Settings
Value
Enter a name for your project.
Enter the username you use to log in to the organization associated with this project (“home organization”). The username must have the “Modify All Data” permission.
Enter the password for the specified username.
If you are using a security token, enter the value here.
Choose the appropriate environment for your connection
(Developer Edition or Sandbox).
Leave this option unchecked.
Set to a value between 3 and 600 seconds.
If you connect through a proxy, click the Proxy Settings link to open the Network Connections dialog.
For details on these settings, see Force.com Project Properties
.
3. On the Project Contents page, choose Apex and Visualforce.
4. Click Finish to create the project, connect it to the associated organization, and copy components from the home organization into the project in the appropriate folders.
19
Getting Started with the Force.com IDE Quickstart: Using the Force.com IDE
Now that you have created a project, when you edit and save items in the project, the edits are saved to the server. (If the items fail to compile, they are not saved.)
2. Create Apex Components
The following steps create an Apex class and trigger to pre-populate a field on the Accounts tab.
Create a class that populates the
Hello
field on the Accounts tab with the word “World”:
1. In Eclipse, right-click on the project you created in the Package Explorer, and select New > Apex Class.
2. Enter
MyHelloWorld
as the name for the project, leave the other settings as is, and click Finish.
3. The source for the new
MyHelloWorld.cls
class is displayed. Replace the auto-generated text with the following: public class MyHelloWorld {
// This method updates the Description field for a list
// of accounts to read "Hello World".
public static void addHelloWorld(Account[] accs){ for (Account a:accs){ if (a.Description != 'Hello World' )
}
} a.Description = 'Hello World' ;
}
Save your changes.
4. If the IDE asks if you want to save the changes to the server, click Yes.
Next, create a trigger that calls
MyHelloWorld.cls
whenever a new record is created.
1. Right-click on your project in the Package Explorer and select File > New > Apex Trigger.
2. Enter helloWorldAccountTrigger
as the name of the trigger.
3. Click the Object drop-down list and select Account.
4. In the Apex Trigger Operations section, check the before insert checkbox.
5. Click Finish.
6. The source for the new helloWorldAccountTrigger.trigger
file is displayed. Replace the auto-generated text with the following: trigger helloWorldAccountTrigger on Account
(before insert ) {
MyHelloWorld.addHelloWorld(Trigger.
new );
}
Save your changes.
To see your new Apex class and trigger working, log in to your Salesforce organization in a browser and create a new account. You should see the Description field pre-populated with the value “Hello World”.
At this point, you can make changes to the class or trigger in the project. When you save, the changes are automatically saved to the associated organization, assuming no conflicts exist. If you make changes from the organization itself, you must synchronize those changes to the project. For details, see
20
Getting Started with the Force.com IDE Quickstart: Using the Force.com IDE
3. Add Tests
Unit tests are class methods that verify whether a particular piece of code is working properly. Unit test methods take no arguments, commit no data to the database, and are flagged with the testMethod
keyword in the method definition. A rich set of unit tests gives you confidence that your code works correctly and can help you catch bugs when a code change suddenly causes a test to fail.
Note: While you can develop and execute Apex classes and triggers freely in your Developer Edition or Sandbox organization, at least 75% of your code must be covered by automated unit tests before you can deploy it to a production organization.
The steps below create a simple unit test for the Hello World program:
1. Open
MyHelloWorld.cls
and add the test methods below: public class MyHelloWorld {
// This method updates the Description field for a list
// of accounts to read "Hello World".
public static void addHelloWorld(Account[] accs){ for (Account a:accs){ if (a.Description != 'Hello World' ) a.Description = 'Hello World' ;
}
}
}
2. Create another Apex class with the name
MyHelloWorld.cls
. Replace the auto-generated text with the following test class:
@isTest private class MyHelloWorldTest {
// Simple test of the method
// MyHelloWorld.addHelloWorld(Account[]) static testMethod void test_addHelloWorld()
{
// Set up test data set
Account testAcct1 = new Account();
Account testAcct2 = new Account(Description = 'Foo' );
Account[] accts = new Account[] { testAcct1, testAcct2 };
// Execute code with test data
MyHelloWorld.addHelloWorld(accts); // call
}
// Confirm results
System.assertEquals( 'Hello World' , accts[0].Description);
System.assertEquals( 'Hello World' , accts[1].Description);
// Simple test of the trigger helloWorldAccountTrigger static testMethod void test_helloWorldAccountTrigger()
{
// Set up test data set
Account testAcct1 = new Account(Name= 'One' );
Account testAcct2 = new Account(Name= 'Two' , Description = 'Foo' );
Account[] accts = new Account[] { testAcct1, testAcct2 };
// Execute trigger with test data set insert accts;
21
Getting Started with the Force.com IDE Working Offline
}
// Confirm results
Account[] acctQuery = [SELECT Description FROM Account WHERE Id = :accts[0].Id OR
Id = :accts[1].Id];
System.assertEquals( 'Hello World' , acctQuery[0].Description);
System.assertEquals( 'Hello World' , acctQuery[1].Description);
}
3. Save your changes.
4. Right-click on the classes folder in Project Explorer and select Force.com > Run Tests.
For detailed information on testing, see
Testing Code with the Force.com IDE .
Working Offline
Increase your productivity by reducing the time required for saving the projects you create using the Force.com IDE in offline mode, which is the default setting.
By default, you’ll create your projects in offline mode. When you work in offline mode, you avoid compiling your organization’s Apex code each time you save your files. If, however, you have a stable Internet connection and a small- to medium-sized code base, you may wish to toggle your projects to online mode.
Toggle Between Offline and Online Modes
Right-click your project in the Package Explorer and choose Force.com, and then select the mode in which you want to work.
Save Files
When working online, the files you save are saved on the server and then retrieved from the server into your project. When working offline, files are saved locally. You can, however, save files to the server when you right-click the file in the Package Explorer and choose
Force.com > Save to Server. This action is the same as when you save files while working online.
SEE ALSO:
Updating the Force.com IDE
It is recommended that you always use the latest version of the Force.com IDE so you have the latest features, bug fixes, and documentation.
To update the IDE:
1. From Eclipse, select Help > Software and Workspace Center. Alternatively, you can click the Check for Updates link on the
Force.com Start Page.
2. The Software and Workspace Center opens, searches automatically, and provides a link to any relevant updates in the Updates
Available section.
3. Select the Force.com IDE update and click Apply 1 change.
4. In the dialog that opens, confirm that the Install Location is correct and click Update.
5. Accept the license agreement and click Finish.
22
Getting Started with the Force.com IDE Updating the Force.com IDE
6. You are prompted to restart Eclipse; click OK.
After you have updated the Force.com IDE, your projects might also need to be upgraded to the latest version. For more information, see
.
23
Developing with the Force.com IDE
The Force.com IDE allows you to create and edit Apex, Visualforce, and XML metadata components using source code editors that provide syntax highlighting, code assistance, and server-based error checking.
Working with Force.com Projects
The first step is to create a Force.com project associated with your Salesforce organization (the home organization) and download metadata components. You can manage projects and files using the standard views, tools, and commands in the Eclipse IDE workbench, and use features from the Force.com IDE.
•
Use a wizard to create your first project. For details, see Create New Force.com Project .
•
Create or edit the package.xml
project manifest file using the Choose Metadata Components dialog. For more information, see
and
•
Develop in your project and on the server at the same time, with multiple developers accessing the same information. For information on how to refresh data and synchronize changes, see
Writing Code
Once you have created a project, you can use the Force.com IDE to create, edit and manipulate objects and components.
•
to create objects and components, including Apex classes and triggers, and Visualforce components and pages. Each wizard allows you to define properties for the object and creates it with standard attributes and values.
•
•
Execute anonymous blocks of Apex and commit them to the database using the
.
•
Browse schema objects and fields or assemble and execute SOQL queries in the
SEE ALSO:
Force.com Project Basics
Like most integrated development environments, the Force.com IDE organizes application resources into containers called projects.
Unlike traditional software development projects where source code is compiled to create runnable applications, the resources in a
Force.com project live within a Salesforce organization and are copied into the local project for editing.
Each Force.com project is connected to a Salesforce organization, known as its home organization, and contains a set of files which correspond to metadata components stored in the home organization’s database. When you save a file in a Force.com project, it is immediately saved to the server, or if the server finds an error that error message is returned to the Force.com IDE and displayed in the
24
Force.com Project Basics
Note: Because Force.com projects are connected to a live environment, they may be impacted by components running in the home organization but not downloaded into the project. For example, a workflow rule defined in your organization will run in the same transaction as an Apex trigger if both are defined against the same object and the workflow rule’s criteria are met.
tree view. Force.com projects are organized into the following folders:
•
src – This folder contains all of the metadata components in your project. Metadata components are organized into folders, by type.
For a list of types and folders, see
.
•
src/package.xml – This control file, known as the project manifest, determines what metadata components are retrieved from the
.
•
salesforce.schema – Opening this file activates the Schema Explorer for the project’s home organization. For more information
•
Referenced Packages – This folder contains the contents of any managed packages that are installed in the project’s home organization. These files are read only; customizing installed managed packages from the Force.com IDE is not supported.
SEE ALSO:
Add/Remove Metadata Components
Create New Force.com Project
To launch the Create New Force.com Project wizard, select File > New > Force.com Project.
Note: If you do not see Force.com Project in the File > New menu, you are not using the Force.com perspective. You can still create a Force.com project without using the Force.com perspective by selecting File > New > Other > Force.com > Force.com
Project; however, you should use the Force.com perspective because it includes other views and features that aid development.
To activate the Force.com perspective, select Window > Open Perspective > Other > Force.com Perspective.
The New Force.com Project wizard has two pages:
1. On the first page of the wizard, enter the appropriate properties for the project. For details on these settings, see
. Click Next.
Note: When you create a new project, you might be prompted about a new master password. This is a separate password of your choosing required by Eclipse secure storage, and is not associated with your Salesforce credentials. For details on
Eclipse secure storage, see the Eclipse Workbench User Guide.
2. On the Project Contents page, choose which metadata components are retrieved:
Field Description
Apex and Visualforce (classes, triggers, pages, components, and static resources)
Select this option to retrieve only Apex and Visualforce components, including classes, triggers, components, pages, and static resources.
Selected metadata components
Select this option and click Choose... to open the Choose
dialog.
25
Field
Contents of package
None
Force.com Project Basics
Description
Select this option and click Choose package... to retrieve the contents of a particular package. Note that this option is only available when there are packages on the organization you connect to.
Select this option to retrieve no components. You might want to select this option if you are working in a team-based environment where source files are checked out from a source-control system. When creating a project offline, this is the only option available.
3. Click Finish to create the new project.
Note: The selections you make in the New Force.com Project wizard are used to create the package.xml
file, which defines which components from the server are downloaded into your project. To later modify the project contents, right-click your project and choose Properties, and go to Force.com > Project Contents. In special cases you may want to edit the package.xml
file by hand. For information on changing the contents of your project manifests after project creation, see
Project Properties
Use the Force.com IDE’s project properties dialog to modify an existing project: to update organization credentials and connection settings, change the included metadata components, and adjust view settings. To open the project properties dialog, right-click your top-level project folder and select Properties.
The project properties dialog includes standard Eclipse property pages and the following Force.com project property pages.
•
Force.com Project Properties: The properties on the main page determine a Force.com project’s Salesforce connection settings.
Use this page to update your password or security token, change timeout values, or associate your project with a different home organization. For details on these properties, see
Force.com Project Properties .
•
Apex Code Settings: This page allows you to define default logging levels for the tests that execute during your deployments and
•
Force.com Project Contents: This page shows the contents of your project based on the project manifest file ( package.xml
).
To add or remove metadata components from your project, click Add/Remove Metadata Components. If this project contains a package, the server determines which files are retrieved. You can change the contents of the package only on the server, not from this page. When you change project contents, you are prompted to refresh files from the server.
Add/Remove Metadata Components
To add existing components in your home organization to a project:
1. In the Package Explorer, right-click the project and choose Properties.
2. In the Project Properties dialog, expand the node for Force.com and click Project Contents.
3. Click Add/Remove Metadata Components to open the
Choose Metadata Components dialog.
Because a Force.com project is connected to its home organization, simply deleting a metadata file from a project does not always permanently remove it. Depending on whether your intention is to delete a component from the home organization as well as your project, or merely to exclude it from your project, the steps you will take are different.
26
Force.com Project Basics
Note: If you remove a component from a project without deleting it from the server, you can add it to your project again. The component will also be available in other projects that connect to the same server. If you delete the component on the server, the component will not be accessible from other projects. The only way to retrieve it again is by using the Web interface and viewing your Recycle Bin.
To remove a component from the project only:
1. In the Package Explorer, right-click your project and choose Properties.
2. In the Project Properties dialog, expand the Force.com node and click Project Contents.
3. On the Project Contents page, click Add/Remove Metadata Components.
4. Use the Choose Metadata Components
dialog to remove the component.
5. In the Package Explorer, expand the nodes to find the component you want to remove. The project will no longer download the component from your home organization during synchronization, but you still need to delete your local copy of the file.
6. In the Package Explorer, right-click the component and choose Delete.
7. You will be prompted whether you want to delete the file. Click Yes to remove the local copy.
8. In the Remote Delete Confirmation dialog, you will be prompted whether to also delete the component on the server. Click No to leave the server-side component unaffected.
To remove a component from the project and delete it from the server:
1. In the Package Explorer, expand the nodes to find the component you want to delete.
2. Right-click the component and choose Delete.
3. You will be prompted whether you want to delete the file. Click Yes to remove the local copy.
4. Finally, in the Remote Delete Confirmation dialog, you will be prompted whether to also delete the component on the server. Click
Yes to delete the component entirely.
SEE ALSO:
Choose Metadata Components
Use the Choose Metadata Components dialog to specify which Force.com metadata components you want to retrieve in a project. Click a top-level folder to select all components of a particular type. This option will also retrieve new components that are added via the Web interface whenever you refresh from server. (Selecting the top-level folder is the equivalent of adding the wildcard character to the package.xml
file. For more information, see About Package.xml
.)
Only fully editable packages are available; those created in your organization or installed unmanaged packages. Installed managed packages are not available in this list.
Note: A Force.com project is defined by a package.xml
file. While you can edit this file by hand, it's much easier and less error prone to use the Choose Metadata Components dialog to create or edit this file. If you edit the package.xml
file by hand, your changes may be overwritten if you open the Choose Metadata Components dialog. For more information, see
The following controls help you navigate the available components:
27
Force.com Project Basics
Field
Filter
Show only selected items
Select All
Deselect All
Expand
Collapse
Refresh
Description
Enter text to filter all metadata components that start with the letters you enter in this field. You can use the * character within the filter string as a wildcard.
Select this checkbox to show only the items that have been selected. This is useful after you make several selections and want to see only what will be retrieved in your project.
Selects all components.
Deselects all components.
Expands all nodes.
Collapses all nodes.
Refreshes selections from server.
Field-Level Security Warning
Including both objects and profiles in your project will cause profiles to contain field-level security for all of that object's fields. The settings in your project will overwrite field-level security settings on the server when the profiles are deployed. If you are developing in a sandbox where field-level security is not set up correctly, and you deploy to a production organization, you will overwrite the field-level security in the production organization. To prevent overwriting production field-level security, do one of the following:
•
Do not include profiles in your project
•
Only choose object fields for which you want to overwrite the field-level security
•
Make sure your sandbox security settings are exactly the same as your production org
Component Properties
You can use the Component Properties dialog to view the server properties of a metadata component, such as its name, type, status, package and namespace membership, and the date the file was created and last modified.
To view Component Properties:
1. In the Package Explorer, locate the component file you want to view.
2. Right-click the component and choose Properties.
3. Click Force.com Component in the navigation pane, on the left side of the file properties dialog.
Upgrade Project
When you create a Force.com project, it's designed to work with a specific version of the server. When the server is upgraded to the next version, your projects need to be updated so you can have access to the latest features and metadata.
Note: To upgrade a project, the connection settings for username, password, and proxy settings (if applicable) must be up to date.
To upgrade a Force.com project:
1. Right click a project and choose Force.com > Upgrade Project to open the Project Upgrade wizard. (This option only appears if an upgrade is available.)
28
Force.com Wizards
2. On the first page of the wizard, review the information and click Next to continue.
3. On the second page of the wizard, review the full details of what will be changed. If you don’t want to upgrade all of these components, click Cancel. Otherwise click Finish.
4. On the final page of the wizard, review your changes.
5. Click Finish to retrieve the specified components.
Force.com Wizards
The Force.com IDE plug-in provides a set of wizards for creating new objects and components, accessible from the File > New menu
(or the New button in the toolbar).
•
•
•
Create an Apex Class from a WSDL
•
•
•
•
•
•
•
•
Create New Visualforce Component
•
•
Apex Editor
To edit an Apex class or trigger:
1. In the Package Explorer, expand the project node.
2. Apex classes and triggers are in separate folders. Expand the
/classes
or
/triggers
folder and double-click the name of the item you want to edit.
29
Apex Code Assist
3. Use the Source tab of the editor for writing Apex and the Metadata tab for editing the associated metadata file.
Note: The editor has content assistance for all built-in types, including both Apex and XML metadata.
SEE ALSO:
Apex Code Assist
Apex code assist is activated when you begin to type a valid line of Apex in the editor. Code assist opens a list of available code completions that aid in both development speed and accuracy.
To use code assist:
1. Insert the cursor in the editor area.
2. If you are typing a class or variable name, type a dot (“.”) and pause for a moment, and the proposal window opens. Otherwise press
Ctrl + Space on the keyboard to activate the proposal window.
3. Use the mouse or keyboard to select an item from the list.
4. Click or press Enter on a selected line in the list to insert the selection into the editor.
Execute Anonymous View
The Force.com IDE Execute Anonymous view allows you to execute an anonymous block of Apex.
30
Server Synchronization
Anonymous blocks help you to quickly evaluate Apex on the fly, or to write scripts that change dynamically at runtime. For example, you might write a client Web application that takes input from a user, such as a name and address, and then use an anonymous block to insert a contact with that name and address into the database.
The content of an anonymous block can include user-defined methods and exceptions. It cannot include the keyword static
.
You do not need to manually commit database changes made by an anonymous block. If your Apex script completes successfully, any database changes are automatically committed. If your Apex script does not complete successfully, any changes made to the database are rolled back.
After your anonymous block is executed on the server, the Results area in the Execute Anonymous view will display the following:
•
Status information for the compile and execute phases of the call, including any errors that occur.
•
The debug log content, including the output of any calls to the
System.debug()
method.
•
The Apex stack trace of any uncaught script execution exceptions, including the class, method, and line number for each call stack element.
Note: Unlike classes and triggers, anonymous blocks are executed as the current user and can fail to compile if the script violates the user's object- and field-level permissions.
Server Synchronization
When you create a Force.com project, the files you specify in your project manifest are copied from the server (your Salesforce organization) and stored locally on your computer.
Note: The term project refers to the local files on your computer, while the term server refers to the live metadata components in a Salesforce organization.
As you develop in the IDE and make changes to the metadata files in your project, it is possible that you (or another developer or administrator) may make changes to the metadata components directly in the browser from the Salesforce Setup menu. Or if you are working in a team-based development environment, other developers may make changes in the source files in your shared repository.
In either case, when metadata is changed outside your project, your project is not immediately aware of those changes and your files may get out of sync.
There are three actions you can take to keep your project and organization files in sync. All of these actions are available by right-clicking the project src folder and choosing Force.com:
•
•
•
Note: If you receive a save error that updates only your local instance (your local project or source control repository), this indicates that your files are not in sync with the server. To replace project files with server definitions, use Refresh from Server. To push project files to the server, use Save to Server.
SEE ALSO:
31
Server Synchronization
Save to Server
Saving files to the server overwrites the metadata components in your organization with the definition in your project files, then refreshes the local files you saved with new copies from your organization. You can save individual files, or all the files in your project.
To save changes in your project:
•
Click the Save icon, or right-click the src node in the Package Explorer and choose Force.com > Save to Server. This saves all the files in your project to the server.
To save an individual file:
•
Select a component in the Package Explorer and choose Force.com > Save to Server. This saves only the specified file to the server.
Note: If the metadata components on the server have changed since your last save or refresh and a conflict is detected, you may be asked to enter the Synchronize with Server view.
Refresh from Server
To refresh projects, folders, or individual items:
•
In the Package Explorer, right click the item you want to refresh and choose Force.com > Refresh from Server.
Note:
Refresh from Server only refreshes the contents specified in the package.xml
project manifest file. That is, if a file in your project is removed from package.xml
, you no longer receive new versions of that file when performing a Refresh from
Server.
Synchronize with Server
When making changes to your home organization in both the IDE and in the browser, your IDE project files may become out of date.
When your project is out of sync, you have three options: use your project files, use the server files, or compare the differences between the two. To avoid inadvertently overwriting changes made outside your project, Salesforce recommends using Synchronize with Server whenever a conflict is detected. Synchronize with Server opens conflicting files in a diff tool so you can compare and merge them.
To synchronize your project with the home organization:
1. In the IDE, right-click the project name in the Package Explorer or other navigation view and select Force.com > Synchronize with
Server. The first time you select this option, the IDE asks if you wish to display the Synchronize view. Click Yes. If any project files need to be synchronized, the project is displayed in the Synchronize view with a red arrow and X if there are changes in the project component, and with a blue arrow if there are changes in the home organization. If nothing needs to be synchronized, the Synchronize view displays the message “No changes in 'Latest From Salesforce (Workspace)'”, and the number of conflicts at the bottom of the
IDE all show 0.
2. Resolve any reported conflicts. Open the project and the relevant folders until you find the component with a red arrow and X or blue arrow. Right-click the component and select one of the following options, depending on the action you wish to take:
•
Apply server to project: Completely replaces the component with the corresponding item in the home organization.
•
Apply project to server: Completely replaces the corresponding item in the home organization with the component in the project.
•
Open in Compare Editor: Opens the editor so you can inspect each conflict and choose to keep either the home organization change or the component as it is for each conflict. You cannot make any other choice; that is, you cannot overwrite a change in the home organization.
3. Click the save icon when you have resolved all conflicts. You may close the Synchronize view when all conflicts are resolved.
32
Server Synchronization
Note: The Synchronize view may not recognize items in the home organization that are not in the project. In these cases, you can right-click the project name and select Force.com > Refresh from server to refresh the components in a project.
33
Testing Code with the Force.com IDE
To measure your code’s quality, track your code coverage and test case coverage. Use the Force.com IDE to create and execute unit tests for your code’s actions and behaviors and to adjust the granularity of your test runs’ logging.
One of the most important and powerful features of the Force.com platform is its built-in support for automated testing. The Apex language includes the ability to define and execute unit tests, which are pieces of code that verify that your application works the way you intended. Each unit test is defined as a test method, and you can execute your test methods to see which tests are passing or failing.
Regularly executing test methods gives you instant insight into the quality of your code and provides an early warning system for detecting regressions.
There are two common ways to measure your code’s quality using unit tests.
•
Code coverage identifies which lines of code a set of unit tests exercises. Code coverage is reported as a percentage. This metric helps you identify the sections of code that are untested and therefore at greatest risk of containing a bug or introducing a regression.
Each time you run a set of unit tests on the Force.com platform, a code coverage number is returned. A list of uncovered lines of code in the classes and triggers invoked by the tests is also returned.
Note:
The Force.com platform requires at least 75% of your code to be covered by automated tests before you can deploy it to a production organization. We recommend that you strive for 100% coverage. The code coverage restriction is not enforced for sandbox or Developer Edition organizations.
•
Test case coverage identifies real-world scenarios in which you expect your code to execute. Even if you have 100% code coverage, bugs can be hiding in your code. To help prevent bugs, ensure that your test values reflect the full set of real-world possibilities, including corner cases. Test cases are not actual unit tests, but are documents that specify what your unit tests are intended to do.
High test case coverage means that most or all of the real-world scenarios that you have identified are implemented as unit tests.
Developing a rich set of automatic tests gives you confidence that your code works correctly. Having good test coverage can help you catch bugs when a code change suddenly causes a test to fail. Having a robust set of tests helps us help you, too. Salesforce executes all your tests before each major release to help us avoid regressions. We run each test once in the existing version of our service—the one currently in production—and once in the release-candidate version. We compare the results to identify unexpected functionality changes between releases. To ensure robust test coverage, regularly do the following.
•
Create unit tests within the implementation class or in a separate test class. Test classes that are annotated with
@isTest
do not
•
.
•
Configure debugging output and system logs using Apex test run configurations.
Salesforce recommends that you write tests for the following:
Single action
Test to verify that a single record produces the correct, expected result.
Bulk actions
Any Apex code, whether a trigger, a class or an extension, may be invoked for 1 to 200 records. You must test not only the single record case, but the bulk cases as well.
Positive behavior
Test to verify that the expected behavior occurs through every expected permutation, that is, that the user filled out everything correctly and did not go past the limits.
Negative behavior
There are likely limits to your applications, such as not being able to add a future date, not being able to specify a negative amount, and so on. You must test for the negative case and verify that the error messages are correctly produced as well as for the positive, within the limits cases.
34
Apex Test Results View
Restricted user
Test whether a user with restricted access to the sObjects used in your code sees the expected behavior. That is, whether they can run the code or receive error messages.
Note: Conditional and ternary operators are not considered executed unless both the positive and negative branches are executed.
For more information, see “Understanding Testing in Apex” in the
Force.com Apex Code Developer's Guide.
SEE ALSO:
Debug Logs for Apex Test Results
Apex Code Settings: Log Category and Log Level
Troubleshooting the Force.com IDE: Debug Mode
Apex Test Results View
The Force.com IDE’s Apex Test Results view displays the results of your test runs. This view is useful for troubleshooting code, tuning performance, and checking resource usage.
Note: All Apex test execution occurs on the server. Before testing your code, save any changes to the server.
To execute Apex unit tests, select Run > Run Configurations > Apex Test. To create a test run configuration, then select New launch
configuration ( ). To execute the selected test run configuration, click Run.
35
Apex Test Results View
Note: To set log levels for your Apex test runs, use run configurations. Logging settings in your project properties apply only when you’re deploying code.
After the a test run, the Apex Test Runner view displays results. The left pane displays test results for each class and method in the test run. The right pane displays code coverage, the stack trace, system debug logs, and user debug logs. Make sure that your code has better coverage than the code in this sample org!
Debug Logs for Apex Test Results
When you run a test, the output is sent to the log. Debug logs display on the right side of the Force.com IDE’s Apex Test Results view.
•
The first part of the log details the events that occurred during the test run.
•
The next few lines give details on how long it took to execute specific lines of code. This information is useful for performance tuning.
•
The debug log then lists how many resources a program uses and the total amount available for each resource. The Apex runtime engine tracks the resources that every script uses so that a single script doesn’t monopolize the servers. If you write a script that goes over one of the limits, you receive an error message.
To change your logging levels, create or edit an Apex test run configuration. To access your Apex test run configurations, select Run >
Run Configurations > Apex Test. To create a test run configuration, then select New launch configuration ( ).
36
Deploying Code with the Force.com IDE
Once you have created application components and tested them in your own development organization, you usually want to migrate them to a different organization for testing, staging, publication, or production use by end users.
Though each Force.com metadata component lives and runs in a particular organization on Force.com servers, the metadata files you work with in the Force.com IDE are portable from one organization to another. Deploying is the process of pushing your local project files into a different Salesforce organization than your project’s home organization. The Force.com IDE provides the Deploy to Server wizard to guide you through the deployment process.
Before you deploy, you can streamline your deployment process by creating a new project with only the components you want to
deploy. For information, see Create New Force.com Project .
Note: If you deploy to a production organization, you must meet the Apex testing compliance policy: 75% of your Apex must be covered by unit tests, and all of those tests must complete successfully. Additionally, each trigger must have some code coverage.
To open the Deploy to Server wizard, right-click the src
folder of the project and select Force.com > Deploy to Server. You can also select individual classes or triggers, multiple classes and triggers, or the classes
or triggers
folder. Before the wizard opens, the
IDE checks for conflicts between the project and the home organization. If conflicts are found, you are given the option to synchronize before continuing.
The Deploy to Server wizard includes the following pages:
2. On the Archive Options page, optionally create backup files for this deployment and click Next.
page, review the actions to be performed in this deployment. Click Next to execute the deployment.
4. The Deployment Result page displays the result of the deployment. You should see Success displayed at the top of the page. If you do not, review the deployment logs by clicking View Logs. If you need assistance with deployment errors, click Save to save your log file for future reference.
SEE ALSO:
Destination Details
On the Destination Details page, enter the connection settings for the organization you are deploying to.
Field
Username
Password
Security Token
Description
Required. The username you use to log into the organization you are deploying to. The username associated with this connection must have the “Modify All Data” permission. Typically, this is only enabled for System Administrator users.
Required. The password for the username specified.
The security token is appended to your password as an added security measure. If you are using a security token, enter the value
37
Field
Environment
Archive Options
Description
here. For more information, see the Salesforce online help topic
Setting Login Restrictions.
Choose the appropriate environment for your connection:
•
Production/Developer Edition - Choose this option if you are connecting to a production or Developer Edition organization.
•
Sandbox - Choose this option if you are connecting to a sandbox organization. Sandbox organizations have an URL that starts with test
.
•
Pre-Release - Choose this option if you have been given the credentials to connect to a prerelease server.
•
Other (Specify) - Choose this option if you want to connect to a specific instance. If you choose this option, you must enter a value in the
Hostname
field.
Archive Options
The Archive Options page allows you to save a snapshot of the project and the destination organization, respectively, before any changes are made. If you are deploying to a production organization, archive your destination organization to facilitate recovery, in the unlikely event that this is needed. The archive options save a snapshot of the project and the destination organization, respectively, before any changes are made. This facilitates recovery if needed. For deployments to production organizations, you should select both archive options.
Field
Project archive
Destination archive
Description
Select to create an archive of your project (local files).
Select to create an archive of the destination files (files on the server).
Deployment Plan
The Deployment Plan page lists every item available for deployment and the action that will be performed. Each type of action is color coded for quick reference. Select the actions you wish to perform in this deployment.
•
Add (green) - Adds the component to the destination organization.
•
Delete (red) - Deletes the component from the destination organization.
•
Overwrite (yellow) - Overwrites the Deployment Plancomponent on the destination organization. This action is available when no differences between the project and server organization for the component are found. This option is not selected by default when files are identical.
•
No Action (grey) - Clear the checkbox next to the component to take no action.
The following controls help navigate the available components:
38
Deployment Plan
Button
Select All
Deselect All
Refresh Plan
Description
Click to select to deploy all items.
Click to remove all items from deployment plan.
Click to refresh available objects.
Click Validate Deployment to check the likely success or failure of the deployment. The Test Deployment Results View displays either a Success or Failure icon along with the reasons for any failures. Click View Logs to view details. Close the window to return to the
Deployment Plan page.
39
Download
Advertisement
Key features
Apex, Visualforce, and metadata component editing
Wizards for rapid object and component creation
Code assistance and syntax highlighting
Server-based error checking
Test execution and code coverage analysis
Deployment tools for seamless deployment
Integrated help documentation
Interactive debugger for thorough code analysis
Frequently asked questions
The Force.com IDE is an integrated development environment (IDE) for building applications on the Salesforce platform. It provides tools for coding, testing, and deploying Salesforce applications.
You can use the Force.com IDE to develop applications using Apex, Visualforce, and metadata components.
You can create a new Force.com project using the New Force.com Project wizard. This wizard will guide you through the process of connecting to your Salesforce organization and setting up your project.
You can test your code using the Force.com IDE’s built-in test runner. This tool allows you to execute Apex unit tests and view the results. You can also use the IDE to analyze code coverage and identify areas of your code that are not adequately tested.
You can deploy your code to Salesforce using the Force.com IDE’s deployment wizard. This wizard will guide you through the process of packaging your code and deploying it to your Salesforce organization.