Mystery Solved - Data did it!

Sometimes adding data to your Salesforce Org can be tricky.  Even though here at CRM Manager we have done a number of data loads, there can always be some surprises.  Like when you just got done coding, everything is working as planned and then the client comes to you and asks if they can reload data – Products to be exact.  At first, it seems like a legitimate request: a reload of Products that will mimic what they want to do in their production org.  Nothing to complicated, so you agree to move forward with the refresh.  After the reload has been completed, the next day becomes your worst nightmare.  The following red error message starts to appear on your VisualForce page: NewProd:theform:j_id1:theblock:j_id30: Validation Error: Value is not valid.  At first glance the message doesn't even make sense to you.

Mystery Solved - Data Did It! - Blog Image

Your first thought is to exam the code.  Something in the code is not agreeing with the new data.  So you look at the code line by line, add validation, and even error handling, but the message still appearing makes no sense to you.  Next option, turning to co-workers to see if they have ever encountered this encrypted message before, but they are just as baffled.  Before total frustration sets in, you turn to Google.  After googling the error message, you find several boards where others who are seeking the answer that you so desire.  A couple of the boards have solutions, so you try them.  Rewriting code and changing the order you in which you execute the page still doesn't get rid of the error message, so you go back to banging your head on the keyboard.

On the second day it dawns on you - What if it isn’t the code?  What if it is something in the data?  Let’s agree, we have all been there. Validation Rules that are added to the Production Org and not to the Sandbox always provide a challenge for test code coverage, but we'll save that for another blog.  Now, back to our error.  While making sure that you don’t alarm them of the torture they've caused you for the past two days, you ask the client for the data file that was loaded.  As you examine the file, everything seems fine.  It looks clean, so you decide to reload it yourself.  Not surprisingly the error message is still there.  As one last effort before calling it a day, you look deeper into the data to find the problem. Right before your very eyes there are double spaces in the product code name. Yes, DOUBLE SPACES has caused two days of torture, rewrite, and a headache!

Here is the problem: When you have a selectList on your VisualForce page, the getter is when you submit the page.  The value that is submitted to the server is checked against the list of options to make sure that it’s valid, but when the selectList is loaded and the double spaces are removed, only single spaces are shown on the screen.  So when the validation occurs, the two values do not match.  Hence, the encryptic message that has plagued you.

Data can break your code.  It is wise to look at it with an eagle eye.  Spaces, apostrophes, and other special characters can cause many developers headaches.  It is good to analyze your data before you start developing.  It is good to know what the client plans on loading or reloading into the org too.  A lot of the development is made up data that sometimes does not reflect the true data that the code will be processing in the production org.  Sometimes no one ever thinks about the data until it is too late.

CRM Manager can help you understand what best fit your needs.  We have experience developers that work with our consultants to accomplish a variety of tasks.

Blogcrm-manager-admin