The Silver Lining

Lessons & Learnings from a salesforce certified technical architect.

Posts Tagged ‘inheritance

Salesforce: Polymorphism driven by Apex class inheritance

with 9 comments

Polywhatsthatnow? Polymorphism ” is the ability of one type, A, to appear as and be used like another type, B.

It is a facet of OOP and can best be described using the good ol’ example of the ‘Shape’ class problem (thanks Java!). Let’s suppose we’d like to create an application that drew a number of shapes on a page. At the time of analysis we know that we want to immediately support circles, but to future-proof our application we need to support the drawing of any shapes. Being Pretty Darn Good Developers(tm) we realise we should create a Shape class that has a single method used to draw itself, and any specific shapes should be derived from this class, and override that method. Make sense? Didn’t think so. Read the rest of this entry »

Advertisements

Written by Wes

December 23, 2009 at 2:04 pm

OOP in the Salesforce Cloud – ReCaptcha Revisited

with 5 comments

Can I get a OOP OOP?! That’s right folks, OOP is alive and well on the Force.com platform, and over the past few months I’ve had some pretty thrilling experiences implementing projects using those trusted sidekicks Encapsulation, Polymorphism and trusty ol’ Abstraction. There is some pretty sweet documentation on the subject, but I thought I’d demo something supercool I learnt by combining two articles from the Force.com wiki. Read the rest of this entry »

Written by Wes

October 1, 2009 at 3:53 pm

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: