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());
 
  }
 
 }
 
}

Friday, May 24, 2013

Goldmine SQL Query to Filter on Date

Below is a basic query that will output the results of all ContHist records from 1/1/2009 and forward.

select * from CONTHIST where ondate > '2009-01-01'

Wednesday, May 22, 2013

Compare Two Blocks of Text

Ran across this nice little free online tool recently that compares 2 blocks of text. This is helpful if you are looking at code that could have been updated and pulling out those differences...

http://www.diffchecker.com

Friday, May 17, 2013

Mass Upload Pictures to Rich Text Field

There is a lot of confusing stuff out there about mass uploading pictures into a rich text field. Below is one thing I have found by testing actually works pretty well.

Process:

  1. Upload image as an attachment into Salesforce against the record the picture is being added to.
  2. Use that success file to create a new CSV file with the following attributes.
    1. The ID of the record having the image inserted
    2. A column that will have the following text
<img alt="User-added image" src="https://c.na14.content.force.com/servlet/servlet.FileDownload?file=00Pd0000003Uf0n"></img>

The 'User-added image' can be replaced with the name of the contact, or not replaced at all. Follow the steps below to fill out the hyperlink:

  1. Add an image to any record in your Salesforce org as an attachment
  2. Open up the attachment
  3. Right click on 'View file' and select 'Open link in a new tab' (this is the option for Chrome)
  4. Copy the url that appears on the new tab, this is the base for the image link
  5. It will take some excel manipulation, but you will need to use the success file for the attachment upload and replace the ID at the end with the ID of all attachments uploaded.
In the end you will only need 2 columns in the file that is uploaded. One being the ID of the record that is receiving the picture, two being the img url from above.