The Silver Lining

Lessons & Learnings from a salesforce certified technical architect.

Archive for June 2009

Salesforce, Bugs & You

with 3 comments

Bugs. Bleh. As far as I know Salesforce doesn’t maintain a list of ‘Known Issues’ and sadly this can mean hours poring over code, trying to find where you went wrong, and eventually finding that it wasn’t your code at all. Of course it wasn’t, because you are perfect. Go on give yourself a hug.

To this end I’ll post bugs as I find them and if you feel like contributing, mail me a few of your own. Some buggy areas are quite obscure, so I’ll start with a common one, the infamous ‘Null Param passed by a CommandButton’. Dun dun duh. Read the rest of this entry »

Written by Wes

June 12, 2009 at 4:54 pm

Visualforce & Dynamic CSS

with 15 comments

When I started working on the Force.com platform CSS was an area that made me sad a bit. Deep down. Overriding the Salesforce CSS is a nightmare and I would recommend you don’t begin the dark and daunting journey down that path. Rather start afresh, you’ll thank me later.

That said, dealing with CSS on the platform can still be a timeconsuming task. Especially if you are incorporting images into your pages using CSS. My initial process was something similar to this:

  1. Create a stylesheet and some styles. Hopefully you’ve done a good job because you have no way of quick-previewing the result.
  2. Include said stylesheet and all referenced images in a zip file. Take care to preserve the directory structure so that you can reference all stylesheet and image files correctly.
  3. Upload the zip file as a static resource.
  4. Create references to the stylesheet in appropriate pages.
  5. View page. Realise you need to move one of your outputPanels 3px right. Be sad. Deep down. Goto 1.

Read the rest of this entry »

Throwing Custom Apex Exceptions

with 4 comments

Throwing custom exceptions is something that most Java developers expect to be able to do when working with Apex code, and indeed it is possible. It isn’t very well documented, but I managed to stumble across this solution after some experimentation.

Usually I would expect an exception to be thrown using syntax at least similar to

throw new Exception('Don\'t be a silly user.');

However this syntax will give the follow error: Type cannot be constructed: Exception

Instead you have to create a new exception class with extends the Apex Exception class

public class myException extends Exception {}

And then throw that new exception

throw new myException('Don\'t be a silly user.');

That’s just the beginning of course, you could create some pretty fancypants error handling in your custom exceptions. The world is your oyster, now all your need is some Tabasco and lime.

Written by Wes

June 11, 2009 at 8:46 am

Dynamic Custom Labels

with one comment

I know what you’re thinking, ‘this is cRAzY talk’. But do not doubt my friend, Salesforce has a very powerful translation framework.

Besides being able to change the language used by the Salesforce standard areas with the flick of a picklist, you can include translatable Custom Labels in most of your custom application. To do this you will need to request that the ‘Translation Workbench’ feature be enable for you Salesforce development environment, after which you will find new areas in your ‘Setup’ menu.

Post enablement you can then create a Custom Labels and include them where necessary within your code. This can be done within a VisualForce page like so

Read the rest of this entry »

Written by Wes

June 10, 2009 at 5:11 pm

VisualForce Tag Cloud Component

with 2 comments

Tag clouds are nothing new on the interwebs, but there is some debate as to which sort of implementation is best. In this debate I prefer the simplest solution [insert further debate as to the definition of ‘simplest’ here] which I propose to be a simple unordered HTML list with some CSS styling.

Furthermore, wouldn’t it be great if this solution were dynamic, thus enabling you to create tag clouds specific to a particular application context?. Rhetorical question, of course it would be. To this end I’ve created a component that utilises a controller, mostly dynamic in nature.

To start with, let’s have a look at the component code Read the rest of this entry »

Written by Wes

June 9, 2009 at 5:33 pm

Instantiating an empty list of SObjects

leave a comment »

You’re building a dynamic Apex class so general you’re thinking about promoting it to colonel. You’ve slogged through the Salesforce documentation on the topic, a feat in itself, but are having issues instantiating an empty list of SObjects to be processed in some way.

If you attempt to do this in the seemingly Salesforce manner i.e.


List<SObject> sobjects = new List<SObject>();

You will receive the following error: Compile error: Only concrete SObject lists can be created

This can be rather frustrating as this type of data structure is one of the more commonly used. There are however 3 workarounds, one slightly more elegant than the rest.

NB myObject is a SObject.

List<SObject> sobjects = Database.query('select id from ' + myObject.getSObjectType() +' where id=null');
String searchquery='FIND\'xxx\'IN ALL FIELDS RETURNING '+ myObject.getSObjectType() +'(name)';
List<List<SObject> searchList=search.query(searchquery);
List<SObject> sobjects = searchlist[0];

or finally you could use a wrapper class (I’m a huge fan of wrapper classes on this platform)

List sobjects = new List();

public class myObject{

sObject obj {get; set;}

public myObject(sObject obj){
this.obj = obj;
}

Gratefully this is not a problem you will encouter often, but it is a complex area that can be further complicated by workarounds. But what doesn’t kill you (usually) makes you stronger.

Written by Wes

June 8, 2009 at 12:13 pm

Salesforce Managed Packages

with 13 comments

This is one area of the Salesforce.com platform that I’m no fan of.

In short, you code a complex application and it’s beautiful. You marvel at the wonder of the sleek UI, the intelligent complexity of the code, and the comprehensive unit testing you’ve implemented. Now you wish to package your application up, advertise it briefly and have the customers pour in. Not so fast my friend.

Packaging can be a nightmare, and there are certain hurdles to this step that you won’t find officially documented. Read the rest of this entry »

Written by Wes

June 6, 2009 at 4:38 pm

%d bloggers like this: