Qurra Muzani reported,

The Prophet of Allah ﷺ used to sit with a group of his companions, among whom was a man whose young son would come up from behind him and sit before him. The boy died, and the man stopped attending the gathering out of grief over his son. The Prophet ﷺ noticed his absence and asked, "Why do I not see so-and-so?"They replied, "Messenger of Allah, the little son you used to see has died."The Prophet ﷺ then met him and asked about his son, and the man told him that he had died. The Prophet ﷺ offered him condolences, then said, "So-and-so, which would you prefer, to enjoy his company throughout your lifetime, or that tomorrow you come to any of the gates of Paradise and find that he has gone ahead of you and is opening it for you?"The man said, "Prophet of Allah, that he should go ahead of me to the gate of Paradise and open it for me is far dearer to me."The Prophet ﷺ said, "Then that is yours."

Azami 3544

Sahih

عن قرة المزني، قال

كان نبي الله ﷺ إذا جلس يجلس إليه نفر من أصحابه، وفيهم رجل له ابن صغير يأتيه من خلف ظهره فيقعده بين يديه، فهلك فامتنع الرجل أن يحضر الحلقة لذكر ابنه، فحزن عليه ففقده النبي ﷺ فقال: ما لي لا أرى فلانا؟ قالوا: يا رسول الله بنيه الذي رأيته هلك، فلقيه النبي ﷺ فسأله عن بنيه فأخبره أنه هلك فعزاه عليه ثم قال: يا فلان أيما كان أحب إليك أن تمتع به عمرك، أو لا تأتي غدا إلى باب من أبواب الجنة إلا وجدته قد سبقك إليه يفتحه لك قال يا نبي الله بل يسبقني إلى باب الجنة فيفتحها لي لهو أحب إلي قال: فذاك لك.

الأعظمي 3544صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Funerals
Chapter
Dying person
Section
Offering condolences
Numbering
Jami al-Kamil 3544 (2nd edition)
Azami 3544