Anas bin Malik reported,

The Prophet ﷺ reported that three men from a people of the past set out seeking provision for their families when rain caught them, so they entered a cave. A massive rock fell across its mouth, sealing it so completely that they could not see even a chink of light through it.They said to one another, "The rock has fallen, the tracks are wiped away, and no one knows where you are except Allah. So call upon Allah by the most reliable of your deeds."One of them said, "O Allah, if You know that I had two parents, and I used to milk for them into their cup and bring it to them. If I found them sleeping, I would stand at their heads, unwilling to disturb their sleep, waiting until they awoke whenever they awoke. O Allah, if You know that I did this seeking Your mercy and fearing Your punishment, then relieve us."A third of the rock moved away.The second said, "O Allah, if You know that I once hired a worker for a job he was to do. He came to me seeking his wages while I was angry, so I rebuked him, and he went away leaving his wages behind. I gathered them and invested them until they grew into a great deal of wealth. Then he came back seeking his wages, and I handed all of it over to him. Had I wished, I could have given him only his original wage. O Allah, if You know that I did this seeking Your mercy and fearing Your punishment, then relieve us."Two-thirds of the rock moved away.The third said, "O Allah, if You know that a woman attracted him, and he offered her a payment. When he gained power over her, she pleaded with him for the sake of her honor, and he handed over the payment to her and let her go. O Allah, if You know that I did this seeking Your mercy and fearing Your punishment, then relieve us."The rock moved away, and they walked out together in haste.

Azami 10969

Sahih

عن أنس

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

الأعظمي 10969صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Supplications, remembrances, and prayer upon the chosen Prophet ﷺ
Chapter
Legitimate means of seeking nearness in supplication
Section
Seeking nearness to Allah through righteous deeds
Numbering
Jami al-Kamil 10969 (2nd edition)
Azami 10969