Ali bin Abu Talib reported,

We were with the Prophet ﷺ at Baqi al-Gharqad for a funeral when he said, "There is not one of you whose place in Paradise and whose place in the Fire has not already been written."They said, "Messenger of Allah, then should we not simply rely on that?"He replied, "Work, for everyone is enabled toward what he was made for." Then he recited, "As for the one who gives and is mindful of Allah and affirms the truth of goodness" [Layl 92:5–6] up to His words "for hardship" [Layl 92:10].Musaddad narrated to us, Abdul-Wahid narrated to us, Amash narrated to us from Saad bin Ubayda, from Abu Abdul-Rahman, from Ali رضي الله عنه, who said, "We were sitting with the Prophet ﷺ," and he then related the hadith in similar terms.

Bukhari 4945

Sahih

حدثنا أبو نعيم حدثنا سفيان عن الأعمش عن سعد بن عبيدة عن أبي عبد الرحمن السلمي

عن علي رضي الله عنه قال

كنا مع النبي ﷺ في بقيع الغرقد في جنازة فقال ما منكم من أحد إلا وقد كتب مقعده من الجنة ومقعده من النار فقالوا يا رسول الله أفلا نتكل فقال اعملوا فكل ميسر ثم قرأ {فأما من أعطى واتقى وصدق بالحسنى} إلى قوله {للعسرى} حدثنا مسدد حدثنا عبد الواحد حدثنا الأعمش عن سعد بن عبيدة عن أبي عبد الرحمن عن علي رضي الله عنه قال كنا قعودا عند النبي ﷺ فذكر الحديث نحوه

البخاري 4945صحيح
Contents
Reference
Commentary
Ayat
Collection
Sahih Bukhari
Book
Tafsir
Chapter
His saying, "As for he who gives and fears Allah"
Numbering
Darussalam 4945
Bukhari 4945