Thereupon one of them supplicated,
“O Lord, my parents were very old, and I used to offer them their nightly drink of milk before my children and the other members of the family. One day I went astray far away in search of green trees and could return only after my parent had gone to sleep. When I had milked the animals and brought their nightly drink to them. They were fast asleep, but I did not like to disturb them, nor would give any part of the milk to my children and other members of the family till after my parents had their drink. Thus, with the vessel in hand, I awaited their awakening till the flush of dawn, while the children cried out of hunger at my feet. When they woke up, they had their drink. O Lord, if I did this thing seeking only your pleasure, then do relieve us of the distress wrought upon us by this rock.”
Thereupon, the rock moved a little but not enough to let them pass out.
Then the third supplicated:
“O Lord, I hired some labourers and paid them their dues, but one of them left leaving behind what was due to him. I invested it in business and the business prospered greatly.
After a while, the labourer came back and said: ‘O servant of Allah, hand over to me my wages.’ I said to him: ‘All that you see is yours; camels, cattle, goats and slaves.” He said: ‘Don’t play joke with me, O servant of Allah.’ I assured him: ‘I am not joking.’ So he took all of it sparing nothing. O Lord, if I did this seeking only for your pleasure, do relieve us of our distress.”
The rock then moved away, and all the three came out of the cave safe and sound.
From the story within this hadith we learn of one of the permissible forms of tawassul, which is to ask Allah by your good deeds which you have done in the past. Note that every time one of the men mentioned his good deed, he put a condition on it that Allah judge whether it was performed sincerely, as a deed which is performed without sincerity will not be accepted by Allah. We also learn some of the noble types of deeds, which include looking after ones parents, avoiding a sin even when one is in the last seconds of committing it, and being careful and wise with responsibilities that are trusted to you.