There is a beautiful story in the Upanishads, the sacred vedic texts:
A rishi called Jadabharatha somehow became attached to a deer he had rescued. He was living the life of a renunciate but he got attached to this deer.
From morning till night, he used to spend his time taking care of that deer. When he was dying, he was not able to forget the animal. He started worrying about the deer, ‘Oh! Who will take care of the deer? What will happen to it after my death?’
When he died, in the next birth, he was born as a deer.
Beautifully the verse in the Upanishad says that whatever you think in your last moment, you become that!
Some people think very cleverly, ‘Let me live my whole life the way I want to live. In the last few moments, I will remember god and chant His name and enter heaven somehow.’ Please be very clear, only that which you thought of in your whole life, will come up when you leave the body. Don’t think that at that last moment you can play the game!