Monday, July 29, 2013

Eclipse Force.com IDE Issue Resolved

Over the years I have run into problem after problem with the Eclipse Force.com IDE. Once it is working I try not to touch anything to prevent it from breaking again!

I wanted to outline the issue I recently ran into and how I resolved it.

Whenever I tried to create a project or refresh an exiting project I was getting this error:

com.salesforce.ide.api.metadata.types.Metadata$JaxbAccessorF_fullName cannot be cast to com.sun.xml.bind.v2.runtime.reflect.Accessor

After researching it, primarily on the Developer discussion boards (this one specifically: http://boards.developerforce.com/t5/General-Development/Unable-to-refresh-resource/m-p/333759#M60381 ) I tried the solutions that were suggested in changing workspaces and running as an admin and neither of those worked. So I decided to downgrade the Java JRE from 7 to 6 and this worked!

I went here to download JRE 6 http://www.oracle.com/technetwork/java/javase/downloads/jre6-downloads-1637595.html then before I installed JRE 6 I uninstalled JRE 7 from the control panel.

To check what version of Java was currently running I went to the command prompt and typed in 'java -version' below is what output:

java version "1.7.0_05" ..... before I removed version 7

java version "1.6.0_34" .... after in uninstalled version 7 from the control panel

After that I started up the force.com IDE and everything worked perfectly! 

Tuesday, July 23, 2013

Using Apex Variables in SOQL and SOSL Queries (SOQL IN Clause)

I spent some time looking for this documentation around using the SOQL IN clause with a list and wanted to save it.

I basically want to run a SOQL query that is looking at a list of String values in the WHERE condition, like this:

// An IN-bind with an Id list. Note that a list of sObjects
// can also be used--the Ids of the objects are used for 
// the bind
Contact[] cc = [SELECT Id FROM Contact LIMIT 2];
Task[] tt = [SELECT Id FROM Task WHERE WhoId IN :cc];

// An IN-bind with a String list
String[] ss = new String[]{'a', 'b'};
Account[] aa = [SELECT Id FROM Account 
                WHERE AccountNumber IN :ss];


http://www.salesforce.com/us/developer/docs/apexcode/Content/langCon_apex_SOQL_variables.htm

Sunday, July 21, 2013

Basic For Loop

Below is a basic example of a for loop. I always seem to need to need this and forget the exact context.


trigger OpportunitySubmitForApproval on Opportunity (after update) {
 
 for (Integer i = 0; i < Trigger.new.size(); i++) {
 
  if (Trigger.old[i].Probability < 30 && Trigger.new[i].Probability >= 30) {
 
   // create the new approval request to submit
   Approval.ProcessSubmitRequest req = new Approval.ProcessSubmitRequest();
   req.setComments('Submitted for approval. Please approve.');
   req.setObjectId(Trigger.new[i].Id);
   // submit the approval request for processing
   Approval.ProcessResult result = Approval.process(req);
   // display if the reqeust was successful
   System.debug('Submitted for approval successfully: '+result.isSuccess());
 
  }
 
 }
 
}