The Prophet ﷺ said, "When a person dies, his deeds come to an end except for three, an ongoing charity, beneficial knowledge, or a righteous child who prays for him."
حدثنا سليمان بن داود حدثنا إسماعيل أنبأنا العلاء عن أبيه
أن النبي ﷺ قال إذا مات الإنسان انقطع عنه عمله إلا من ثلاثة إلا من صدقة جارية أو علم ينتفع به أو ولد صالح يدعو له
Its chain of transmission is sahih. It is found in Muslim, 3/1255, no. 1631, in the Book of Wills, on the reward that reaches a person after his death. It is likewise found in Abu Dawud, 3/117, no. 2880, in the Book of Wills, on what has been said about giving charity on behalf of the deceased, and in Tirmidhi, 3/651, no. 1376, in the Book of Rulings, on endowments, and in Nasai, 6/251, no. 3651, in the Book of Wills, on the merit of giving charity on behalf of the deceased, all of them with closely similar wordings.