Visualforce & Dynamic CSS

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 more

Throwing Custom Apex Exceptions

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: 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: And then throw that new exception: 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.

Dynamic Custom Labels

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 more

VisualForce Tag Cloud Component

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 more

Instantiating an empty list of SObjects

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. [code language=”java”] List<SObject> sobjects = new List<SObject>(); [/code] 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. [code language=”java”] List<SObject> sobjects = Database.query(‘select id from ‘ + myObject.getSObjectType() +’ where id=null’); [/code] [code language=”java”] String searchquery=’FIND\’xxx\’IN ALL FIELDS RETURNING ‘+ myObject.getSObjectType() +'(name)’; List<List<SObject> searchList=search.query(searchquery); List<SObject> sobjects = searchlist[0]; [/code] or finally you could …

Read more

Salesforce Managed Packages

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 more

An Introduction

Salesforce.com is an ever increasing presence on the interweb. They’re leaders in a market that promises to be the next generation of software development, that of cloud computing. Google, Amazon and Mosso are some other names that have realised the current and potential power of developing and/or hosting in the cloud and it’s an area that I’m glad to be involved in from so early on.

Although this tech is not new, it is still young, and I’ve started this blog as a way to contribute to the growing community of Cloud Computing developers. The teething problems are still quite apparent in this industry, and as someone who’s been heavily involved in the technology for some time, I’m starting to see how problematic certain aspects of this type dev are(although the benefits far outweigh the drawbacks).

Read more