i would first recommend cleaning out the sand as soon as you can. From the looks of it, the sand that you ahve in there is shorting out the connector and it thinks that you plugged it into something.
Once you are certain that it's completely dry, useing a can of compressed air, carefully blow out the sand. you can also use a plastic spudger (like the one sold here Spudger) to carefully remove the sand. i do not recommend anything metal as that may cause more damage if you short out anything else. I do recommend first to turn off the phone while this is happening, or better yet, remove the dock connector from the iPhone by following the guide here iPhone 4 Dock Connector Replacement
it's not an easy repair but you might need to replace the dock connector if you cannot get the sand out or if the error does not go away.