The Silver Lining

Lessons & Learnings from a salesforce certified technical architect.

Archive for June 2009

‘With Sharing’ Keyword

with 5 comments

Recently I came across a rather confusing situation with my application. I had whittled down my profiles; implemented a marvelous role hierarchy; and a number of sharing rules, and although my application was functionally restricted i.e. object-level access, field-level access etc., the data didn’t seem to be restricted by the sharing model i.e. I could see data created by user A when logged in as user B, even though I had explicitly disabled this behaviour.

The application I’m developing may not be the same or even similar to yours, especially since I don’t use any standard pages. I suspect that if I had use more of the standard functionality I may have guessed at the solution a bit earlier. Read the rest of this entry »

Written by Wes

June 30, 2009 at 1:54 pm

Posted in Apex, SalesForce

Tagged with , , ,

SOQL ‘Distinct’ Keyword

with 16 comments

It doesn’t exist. Sad but true.

In SQL there is a clause that ensures a duplicate free result set is returned by any query you issue e.g. You want to retrieve a duplicate free list of first names from the table clients. The column holds the following values: Alice, Bob, Alice. In Oracle SQL you would use the following query (and it would return the names Alice and Bob each listed once)

FROM clients;

Unfortunately SOQL doesn’t have this capability although there is an Apex trick that can be employed as a work-around. Read the rest of this entry »

Written by Wes

June 28, 2009 at 3:54 pm

Posted in Apex, SOQL

Tagged with , , , , , Anonymous Blocks

with one comment

Anonymous Blocks. Where have you been all my life? Right under my nose apparently. I am embarrassed to say I’ve only discovered this little jewel of the platform recently, and although I’ve managed without it, I’m pretty sure that it’ll be a regular feature in my development experience.

What are they you ask? It’s simply the ability to execute a bit of Apex code on the fly. This is awesome^6 at least. Often during the development process you need to clean your data. Either you’ve changed your logic and that data is affecting functionality, or perhaps you need to remove data en masse. This is simple with Anonymous Blocks, just write up a short script that will restore your data to an ‘initial’ state and save it for future use. Read the rest of this entry »

Written by Wes

June 27, 2009 at 8:14 pm & Case-Sensitivity

with 5 comments

pnf2ycurh4The platform is case-insensitive. Mostly. It’s difficult to find information on which areas are case-sensitive so I’ve compiled this list of what I’ve discovered thus far(I’ll add notable cases as I encounter them). Read the rest of this entry »

Written by Wes

June 22, 2009 at 2:40 pm

VisualForce Component Ids & Javascript

with 33 comments

I have retired this approach in favour of a much neater solution that can be found here.

Salesforce used in conjunction with JavaScript and Ajax can be pretty smashing. I’ve used a number of JavaScript libraries that make you want to high-five yourself when implemented. There can(and probably will) be some frustration while you bend a library and make it fit within the Salesforce framework, although Ron Hess has some pretty sweet examples for you to pore over.

One simple frustration I’ve come across is that of retrieving elements by Id. Salesforce has an intelligent scheme in place which ensures that HTML elements don’t have duplicate Ids and therefore conform to W3C standards. Read the rest of this entry »

Written by Wes

June 17, 2009 at 6:00 pm

Datatable VS Repeat

with one comment

A long long time ago, in an office not far away I pondered the need for so much variety in the VisualForce ‘structural’ component library. I mean, dataTables, pageBlockTables, outputPanels, panelGrids, repeats, panelBars.. jeez Louise. And when would I use them all? How should I combine them? If I type google in google will I break the Internet? Okay, I didn’t really ponder the last one, everyone knows that’s true.

Nowadays I’d like to think I have a feel for what to use, and when. More specifically I’m going to dig into when to use dataTables over repeats, and vice versa(The only real difference I can find between pageBlockTable and dataTable is that dataTable has a cool onhover JS handler that highlights the currently onhovered row, so I’m totally going to ignore pageBlockTable. Speak to the hand pageBlockTable, because the face ain’t listening). Read the rest of this entry »

Written by Wes

June 16, 2009 at 6:15 pm

Salesforce Savepoints

with 5 comments

Transaction control is an important part of any system that interacts with a database and Salesforce has neat ways of implementing said control.

Anyone that’s worked with SQL databases will be familiar with savepoints and rolling back, and Salesforce has implemented similar constructs. For those who haven’t heard of these terms wikipedia describes them as

savepoint is a way of implementing subtransactions (also known as nested transactions) within a relational database management system by indicating a point within a transaction that can be “rolled back to” without affecting any work done in the transaction before the savepoint was created.

rollback is an operation which returns the database to some previous state.

As with most things, the importance of these two features is best demonstrated using examples. Read the rest of this entry »

Written by Wes

June 15, 2009 at 7:28 am

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 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

%d bloggers like this: