Force.com Sites Best Practice: Truncate Field Values
Force.com allows you to create text fields that store up to 32,000 characters. This sounds like a lot, but time and time again, we find that our clients (or their customers) want to type huge amounts of data into a single field. When you’re using the native user interface, force.com gives you a nice and easy to understand error message. But, when you’re using Visualforce or force.com Sites, the messaging isn’t always as pretty.
There’s a very simple work around though. You can specify in Apex that field values that are too long should be truncated. Thus ensuring that the record is saved nicely, without requiring you to write a lot of logic and custom error messages. It’s not always ideal, but error pages are even less ideal.
Here’s how the code would look for setting truncation on an Account:
Database.DMLOptions dml = new Database.DMLOptions(); dml.allowFieldTruncation = true; Account a = new Account(); a.setOptions(dmo);
Related posts:


