Getting comfortable with Eclipse
You finally have the Force.com IDE installed, but there's a few more steps you need to take. It probably doesn't look like Eclipse has changed much, so let's fix that by performing the following steps:
- Click on the Window menu and navigate to Open Perspective | Other. A list of available perspectives will appear.
- Select the Force.com option and then click on OK.
The layout of Eclipse should change slightly and also now display Force.com Start Page; you're finally home!
Eclipse is highly customizable and has a long list of settings available from the Preferences menu available in the Window menu (the Eclipse menu on Mac). Before we get underway writing code, here are a few tweaks that we recommend you follow, which will help you have a better coding experience:
- Show line numbers: This is an absolute must! Navigate to General | Editors | Text Editors and check the Show line numbers box.
- Set default perspective: Ensure that Eclipse always starts out in the Force.com perspective. For this, navigate to General | Perspectives, select Force.com, and click on the Make Default button.
- Colors and fonts: You might want to make things easier on the eyes. To do so, navigate to General | Appearance | Colors and Fonts.
- Web browser: Everyone has a personal preference, but you might want to specify an alternate browser when opening web pages from Eclipse. To set this, navigate to General | Web Browser and select your browser.
In addition to these preferences, we also recommend moving the Outline view under Package Explorer. You can do so just by dragging it to the bottom half of Package Explorer. This will increase the size of the editor and make it easier to see more of your code.
If you're like us, you wouldn't like to type things over and over again. Eclipse comes with a Snippets feature that lets you save frequently used code blocks and then use them just by double-clicking on them. You can even use Merge Fields to represent variables that you specify upon use. To get started with your first Snippet, perform the following steps:
- Navigate to Window | Show View | Otherā¦.
- Type in
Snippets
in the filter box. - Select the Snippets option and click on OK. The Snippets panel appears in the bottom portion of Workbench.
- Right-click on the Snippets panel and select Customizeā¦. The Customize Palette window appears.
- Click on the New button and select New Category.
- Change the name of your new category to
Apex
and click on Apply. - Right-click on the Apex category in the list and navigate to New | New Item.
- Click on the new Unnamed Template item.
- Change the name of your new item to
System Debug
. - Change Description to
Outputs to Debug Log
. - Click on the New button to create a new variable.
- Click on the new variable name and change it to
Variable
. - Set Description to Variable Name or String.
- Type
String
in Default Value. - Type the following line of code in the template:
system.debug(${Variable});
- Click on Apply and then OK.
You just created your first Snippet. You can't use it just yet but go ahead and put a sticky on this page so that you can come back later and create more Snippets with useful code. In later chapters, when we are writing code, we'll use this Snippet.