Sort a list of sObjects: quick and dirty -or- elegant

2 Oct

Quick and Dirty

Here is a method that I’ve implemented to sort lists of objects by combinations of fields. I don’t claim that it is pretty, but it has worked for me.

With the help of a method from my other post.

Elegant

Implement the Comparable interface on a sub-class allows a list of the objects to be sorted using a familiar ‘.sort()’ method.

Now that your subclass is setup, you can use the built-in sort method for the instantiated object list.

Pad Number with Leading Zeros

1 Oct

Left pad a number with leading zeroes

Thanks to mauricekremer.dyndns.org for the concept and code. Below is my take on the function.

URL Parameters within Apex and Visualforce

28 Sep

Get a URL parameter from a Visualforce page

Get a map of URL parameters from a Visualforce page

Get URL Parameters in a Visualforce page

This assumes the URL is looks like this, “http://www.salesforce.com/apex/MyPage?urlparm=something”.

Put values into Visualforce page’s URL and load a new page

Method 1: write out the URL

Method 2: Put parameters into a PageReference

Put values into the current test page’s URL in a Test Class

Salesforce Help

$CurrentPage Documentation
Controller Navigation Methods
Visualforce Parameters

Apex Loops, The Simple Things

18 Sep

For loop over a map’s keys (KeySet)

For loop over a map’s values

For loop over a list

For loop over a set