Record ID and Data Retrieval from a VisualForce Controller Extension without a SOQL statement

26 Nov

Retrieve field data for a record using the Standard Controller object in a Controller Extension class

Salesforce Documentation:
Standard Controller Class
StandardController Instance Methods

Define and Initialize a Map, List, and Set in Apex

20 Oct

The syntax for defining a list, map, and set collection with initial values sometimes slips my mind. The lack of () throws me off, so this post is to help out my future self.

List Definition

Set Definition

Map Definition

Defining a List of Maps

Defining a Map of Lists

Defining a Map of Maps

Sample logic to retrieve the nested Map’s value

This function accepts Param1 as the key for the outer map. Param2 is the key for the inner map. TheMap is a map that contains a nested map which will be worked with. First, we see if there is a key value in the outer map that matches Param1. When it contains the key, the next statement creates a reference to the inner map in the variable TempMap. TempMap is checked for the value of Param2, and the value is returned when found. Finally, null is returned when there is not a match.

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.