Friday, June 13, 2014

Tips for Migrating from Eclipse to IntelliJ - Re-learning shortcuts and other Tips



Migrating from Eclipse to IntelliJ:  Re-learning shortcuts and other Tips


As a long-time Eclipse user(Spring Tools Suite and Groovy and Grails Tools Suite), the transition to using IntelliJ was jarring in many ways.  Keyboard shortcuts are different, the layout is different and the way you do things is different.

It is worth it to go through with the transition.  Auto-complete and searching is better.  Logs and consoles are better.  The tooling is better.  There are plenty of articles out there that highlight the changes.  Most importantly though is that it is does everything you need well and is very fast.


Here are some things that will help with your transition:



How to Change the JDK




Setup the JDK locations

Here you will want to setup the location of the Java SDKs you have installed.

Ctrl+Shift+Alt+S -> Platform Settings -> SDKs:  Change JDK


Change the JDK path in IntelliJ
Update the JDK in the IntelliJ IDE

Setup the Project SDK

Then you will need to set the Project SDK

Then go to Project Settings -> Project and change the Project SDK



Set Project SDK in Project Structure
Set Project Java SDK for IntelliJ



Keyboard Shortcuts




Here is a mapping of Eclipse vs IntelliJ keyboard shortcuts.

Here are a couple of the most used:



  • ctrl+n:  Find a file by class name
  • ctrl+shift+f:  Search the entire project within files for a string
  • ctrl+s:  Save all files
  • ctrl+shift+N:  Find Resource

Grails Specific Shortcuts
  • ctrl+alt+G:  Open Grails Command line(Run Grails Target)


Here is a more comprehensive list:

EclipseIntelliJ IDEADescription
F4ctrl+hshow the type hierarchy
ctrl+alt+gctrl+alt+F7find usages
ctrl+shift+uctrl+f7finds the usages in the same file
alt+shift+rshift+F6rename
ctrl+shift+rctrl+shift+Nfind file / open resource
ctrl+shift+x, jctrl+shift+F10run (java program)
ctrl+shift+octrl+alt+oorganize imports
ctrl+octrl+F12show current file structure / outline
ctrl+shift+mctrl+alt+Vcreate local variable refactoring
syso ctrl+spacesout ctrj+jSystem.out.println(“”)
alt + up/downctrl + shift + up/downmove lines
ctrl + dctrl + ydelete current line
???alt + hshow subversion history
ctrl + hctrl + shift + fsearch (find in path)
“semi” set in window-> preferencesctrl + shift + enterif I want to add the semi-colon at the end of a statement
ctrl + 1 or ctrl + shift + lctrl + alt + vintroduce local variable
alt + shift + salt + insertgenerate getters / setters
ctrl + shift + fctrl + alt + lformat code
ctrl + yctrl + shift + zredo
ctrl + shift + cctrl + /comment out lines (my own IDEA shortcut definition for comment/uncomment on german keyboard layout on laptop: ctrl + shift + y)
ctrl + alt + hctrl + alt + h (same!)show call hierarchy
none ?ctrl + alt + f7to jump to one of the callers of a method
ctrl + shift + ialt + f8evaluate expression (in debugger)
F3ctrl + bgo to declaration (e.g. go to method)








Software Development Blogs - BlogCatalog Blog Directory

Friday, June 6, 2014

Salesforce Dynamically Populated List of Checkboxes in Visualforce and Apex



Dynamically Populated List of Checkboxes in Visualforce and Apex



Below you will find details on how to create a dynamic checkbox group on a custom Salesforce page using Apex and Visualforce.

These examples will leverage Visualforce specific tags and Apex specific functionality to accomplish things that you would normally need an external library such as jQuery to acheive.



Dynamic Array of Checkboxes


Dynamically build an array of checkboxes and keep track of which boxes are checked.  Checkboxes will be populated from a SOQL query from a custom object in Salesforce.  Selected options will be tracked and persisted if you re-render the checkboxes.



Visualforce


Command button to refresh list of checkboxes

  <apex:commandButton action="{!refresh}" reRender="customCheckboxPanel" status="loadingDetails">  

This is just an example.  A more practical use of this would be a onchange or onclick event such as if you had checkbox groups on multiple tabs.


Output panel that is refreshed to display dynamic list of checkboxes

  
<apex:outputpanel id="customCheckboxPanel" layout="block">  
                       <apex:actionStatus id="loadingDetails"   
                           startText="Loading..."   
                           stopText=""/>    
                             <br/>  
                             <apex:selectCheckboxes value="{!choices}" layout="pageDirection">  
                               <apex:selectOptions value="{!list}"/><br/>  
                             </apex:selectCheckboxes>  
</apex:outputpanel>  



Apex


This code will go in your controller.

You will have an array of strings that will contain each id of each selected option.

You will also need a method that retrieves the options via a SOQL queries and loads them into selectionOption objects

Choice Array and Get Select Options Method

 
//String array to keep track of the ids of choices  
public String[] choices { get; set; }
  
//List of select options to populate select boxes  
public List<SelectOption> getList() {  
     List<SelectOption> options = new List<SelectOption>();  
       for (Your_Custom_Object__c ow : [  
         SELECT Name,id FROM Your_Custom_Object__c]) {   
         options.add(new SelectOption(ow.id, ow.Name));   
       }    
     return options;   
}   

The id is being set as the value and the Name is being set as the displayed label.  Replace Your_Custom_Object__c with the name of the custom object you want to query.

You should now have a set of checkboxes. Checked options will automatically be tracked in the choices String array.


Checkbox Array Example
Check boxes populated with a SOQL query
Dynamically populated checkboxes




Software Development Blogs - BlogCatalog Blog Directory

Wednesday, June 4, 2014

Viewing DEBUG statements in Salesforce APEX Files using the Browser Developer's Console




How to view System Debug Statements in the Salesforce Dev Console





Use system debug statements in your Apex code to log the info you need.

 system.debug('results ' + results);   


Open up the page and execute the behavior you are trying to monitor using system debug statements.

Choose the Logs tab at the bottom of the console and double-click the most recent log for the page you are monitoring.

i.e. apex/yourpage


Select Apex log file
Select the Logs tab and open your log file

Once the log is open you can either check the "DEBUG ONLY" checkbox or check the "Filter" checkbox and filter on the string "USER_DEBUG" or any custom string you are searching for specifically.  Both options are at the bottom of the console.



Filter for USER_DEBUG events
Set the Filter to only display items containing "USER_DEBUG"

Viewing logs in the browser in your Salesforce Instance


If you are having trouble opening the logs in the Developer Console you can open the logs in a regular browser window.

Go to your Salesforce instance and click "Setup" in the top right corner

Then on the left hand menu, at the bottom click on debug logs:

View logs in a browser on your Salesforce instance
View logs in your Salesforce Instance

Then select the appropiate log, click view or download and you can manually search for DEBUG statements using the find command(ctrl+f).


Software Development Blogs - BlogCatalog Blog Directory