I need to set a random hexa code to each post and this code need to persist in database to future search. I have created a custom function to return a code, but now I need to know how to puts this code into de input text field of metabox if this code not exist.
Yes, it works only for new posts, since std is used when the meta box has not been saved before. For old posts, obviously meta box is already saved. So you need to do some migration. Perhaps you should share with us here ;). I think many users like that.