Wednesday, March 23, 2011

Salesforce.com and validation rules

Salesforce.com supports validation rules that are evaluated when DML is performed on a record. These rules can be defined using formulae (which means you can get far more sophisticated than "required field") and the error messages can be presented in user-friendly language.

This is a far better experience than specifying required="true" for each apex:inputField, which can be too simplistic to meet business rules and will return field labels that may not necessarily be user-friendly (e.g. "Date Customer Last Contacted for Product Category A" is not suitable for customers completing a satisfaction survey).

Unfortunately these validation rules are not evaluated simultaneously - they are worked through one by one until there is an error or no rules are left. This means that for a page with 20 validation rules, the end user may have to fix 'n' click 20 times before they can save the page contents.

The only way I'm aware of at present to perform simultaneous evaluation AND present user-friendly error messages is to codify the validation rules in the controller class - bleagh!

Any better suggestions?

Friday, March 4, 2011

Forcing numeric data type in Excel

Excel data types are particularly significant in the following situations:
  • Formulae that perform comparisons such as Vlookup
  • Using Excel as a data source in a join query when you have poor control over type casts e.g. while using Microsoft Query
You can set the formats of cells, but this won't update until you actually edit the cells. If you have a lot of cells it's not feasible to edit them all individually.

I find the quickest way to force the conversion of text to number is to do the following:
  1. Enter 1 in a cell
  2. Copy the cell
  3. Paste special into the range of cells you want to convert
  4. Specify Value and Multiply
The cells you selected will be converted to numeric type.

Numeric is the easiest as Paste Special has number-specific options. For other data types I think you have to create a copy of the cells using a casting formula and use the calculated values instead of the originals. If I find any faster ways for non-numbers I will update this post.

Monday, February 21, 2011

User friendly object lookups in Force.com

The typical approach to user lookups and searches in form development would be to:
  • fetch a list of object IDs and descriptions
  • display the descriptions to the user and allow them to select
  • return the ID(s)
This is tricky in Force.com because there is one standard object identifier field that is always used for lookups and searches. You can make this field an ID for referential integrity purposes, or you can make it a text field for user readability - but you can't do both.

Another ugliness is that the identifier field can't be removed from the object creation page and is editable by default.

A workaround is as follows:
  • In the object page layout, move the identifier field to the system information section. This shifts it out of the way a bit.
  • Create a custom button that puts a default value into the identifier field
  • Add a workflow rule to copy a value into the identifier field from another field

Friday, June 25, 2010

SQL Server search all table columns code

Codekeep.net has a great stored-proc-free code snippet for text searching SQL Server database columns.

Unfortunately this code fails due to single quotes in the column names of the database I'm working with (I know I know, don't get me started!)

It's a simple fix.

On line 43, replace

@ColumnName

with

replace(@ColumnName,'''','')

Thursday, June 24, 2010

Permissions required to access SQL Server from MS Query

MS Query relies on system stored procedures to perform actions like fetching table lists from SQL Server.

Stored procedures that have been identified as required:

mssqlsystemresource.sys.sp_tables
mssqlsystemresource.sys.sp_datatype_info
mssqlsystemresource.sys.sp_columns

(to be completed)

Thursday, March 25, 2010

Visio Viewer 2007 Red X Problem

Symptom

Red X appears when attempting to open Visio documents from Internet Explorer via Visio Viewer 2007

Resolution

Download and install Visio Viewer 2007 SP2
Download and install Security Update for Visio Viewer 2007 (KB973709)

Originally posted at technet forums by CCI_Dave

Tuesday, February 23, 2010

Recovering lost offline files

See http://www.jacksontechnical.com/article.htm?id=34

The steps are:
1. Download a Microsoft tool called CSCCMD.EXE
2. Run the following command:

CSCCMD /extract /target:c:\yourrestorefolder /recurse

This will pull the entire contents of the offline files repository from c:\windows\csc into c:\yourrestorefolder

Make sure that c:\yourrestorefolder is completely empty when using the /recurse switch.

A common cause of this problem is if you have a storage quota on your network drive and are trying to sync more files from your laptop than you're allowed to keep.