The Messenger of Allah ﷺ said, "When a person dies, their deeds come to an end except for three: an ongoing charity, knowledge that is benefited from, and a righteous child who prays for them."
حدثنا علي بن حجر أخبرنا إسمعيل بن جعفر عن العلاء بن عبد الرحمن عن أبيه
أن رسول الله ﷺ قال إذا مات الإنسان انقطع عمله إلا من ثلاث صدقة جارية وعلم ينتفع به وولد صالح يدعو له
Agreed upon [by Bukhari and Muslim]. Muslim narrated it in the Book of Hudud, chapter on the animal, mine, and well causing injury being exempt from liability, hadith no. 1710, from the hadith of Sufyan bin Uyayna, and Bukhari, hadith no. 1499, from the hadith of Zuhri, through the same chain.There is also a narration on this topic from Jabir [Ahmad, 3/335, 353], Amr Muzani [Ibn Majah, hadith no. 2674], and Ubada bin Samit [Ibn Majah, hadith no. 2675].Muslim also narrated it in the Book of Hudud, chapter on the animal, mine, and well causing injury being exempt from liability, hadith no. 1710/45, from Qutayba, and Bukhari, hadith no. 6912, from the hadith of Layth bin Saad, through the same chain. The hadith of Malik is found in Muwatta, 2/869, in abridged form.