R.C. Sproul dealt with that question here, but of course I have to add my own spin to his sage words. Deathbed, or foxhole, conversion is a sticky wicket. God knows our inmost motives, the thoughts and intents of our hearts, and if a last minute conversion is genuine in His sight, He is the Judge.
That said, I would venture that the vast majority of such “conversions” amount to trying to cop a plea with the Big Guy upstairs. They want to gorge themselves on the world’s cake and still have it for eternity. That’s called presumption, and the all-knowing God won’t buy into your little con game.
The bottom line is really quite simple; if you know you’re a sinner, and that Jesus is the way to the Father, don’t wait to do what you know you have to do. 2 Timothy 3 has something to say about that:
1 But understand this, that in the last days there will come times of difficulty. 2 For people will be lovers of self, lovers of money, proud, arrogant, abusive, disobedient to their parents, ungrateful, unholy, 3 heartless, unappeasable, slanderous, without self-control, brutal, not loving good, 4 treacherous, reckless, swollen with conceit, lovers of pleasure rather than lovers of God, 5 having the appearance of godliness, but denying its power. Avoid such people.
That’s called loving the world more than God, and refusing to give it up.
Only God knows which breath will be your last, and because of our human need to practice denial, it always comes by surprise. So don’t be a fool. It’ll bite you in the end.