Book Image

Learning Apex Programming

5 (1)
Book Image

Learning Apex Programming

5 (1)

Overview of this book

Table of Contents (17 chapters)
Learning Apex Programming
Credits
Foreword
About the Authors
About the Reviewers
www.PacktPub.com
Preface
Index

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:

  1. Click on the Window menu and navigate to Open Perspective | Other. A list of available perspectives will appear.

  2. 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!

    The Force.com perspective in Eclipse

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:

  1. Navigate to Window | Show View | Other….

  2. Type in Snippets in the filter box.

  3. Select the Snippets option and click on OK. The Snippets panel appears in the bottom portion of Workbench.

  4. Right-click on the Snippets panel and select Customize…. The Customize Palette window appears.

  5. Click on the New button and select New Category.

  6. Change the name of your new category to Apex and click on Apply.

  7. Right-click on the Apex category in the list and navigate to New | New Item.

  8. Click on the new Unnamed Template item.

  9. Change the name of your new item to System Debug.

  10. Change Description to Outputs to Debug Log.

  11. Click on the New button to create a new variable.

  12. Click on the new variable name and change it to Variable.

  13. Set Description to Variable Name or String.

  14. Type String in Default Value.

  15. Type the following line of code in the template:

    system.debug(${Variable});
  16. 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.

Creating your first Snippet in Eclipse