All perfect praise be to Allah, The Lord of the worlds. I testify that there is none worthy of worship except Allah and that Muhammad is His slave and Messenger.
This hadeeth was reported by Al-Bukhaari with its chain of narration going back to Hassaan ibn ‘Atiyyah from Abu Kabshah As-Salooli, who said that he heard ‘Abdullah ibn 'Amr ibn Al-'Aas, may Allah be pleased with him, say, "The Prophet said, 'There are forty kinds of virtue; the uppermost of them is to lend a milch she-goat (to someone in order to benefit from it and then return it). The one who practices any of these virtues expecting its reward and believing in the truthfulness of the promise made for it [by Allah] shall enter Paradise.' Hassaan said, 'We tried to count those good deeds of less importance [in reward] than the milch she-goat; we mentioned responding to the Salaam; saying to the one sneezing, ‘May Allah have mercy upon you’; removing harmful things from the road; etc., but we could not count more than fifteen.'" [Al-Bukhaari]
The meaning of the hadeeth is that there are forty virtuous qualities; the best of which in reward is a milch she-goat whose owner gifts to others to benefit from its milk and wool, and then they give it back (to its owner). If someone does one of these forty qualities, hoping for its reward and believing in the reward that Allah and His Messenger had promised for those who does them, Allah will admit him into Paradise because of accepting them. So entering Paradise is due to the favor of Allah, and not due to one’s deeds.
This is the meaning that the author of ‘Awn Al-Ma'bood had stated.
Ibn Hajar when he explained this hadeeth in Al-Fat'h, said:
“The summary of what Ibn Battaal said is that the saying of Hassaan (at the end) does not prevent from the existence of all these virtues, and the Prophet urged us to do many kinds of goodness and righteousness that are uncountable. It is well known that the Prophet knew the forty virtues that he referred to, but he did not mention all of them to us for a meaning that is more beneficial to us than mentioning them, which is fear that listing them would cause some people to be neglectful of other righteous deeds. He (Ibn Battaal) said that he was told that some people tried to enumerate them and found them to be more than forty. He mentioned helping someone in his craft, doing a job for a clumsy person, giving someone a shoe lace, concealing the sins of a Muslim, defending his honor, making him happy, making room for someone in a gathering, guiding to do good, good speech, planting, sowing, interceding [in favor of someone], visiting the sick, hand-shaking, loving for the Sake of Allah, hating for His Sake, sitting together for the Sake of Allah, visiting each other for the Sake of Allah, giving advice, being merciful, and all of these were mentioned in authentic ahaadeeth. One could argue about some of them being less in reward than gifting a milch she-goat. I omitted some of what he had mentioned, which Ibn Al-Muneer criticized, and he said that it is more appropriate not to be concerned about enumerating them, for the reason that was mentioned earlier. Al-Karmaani said, 'All of the things that he mentioned is but conjecture; how did he know that they are inferior in reward to the gift of a milch she-goat?' I said, 'I only intended from what I mentioned of them to get closer to the fifteen of them which were counted by Hassaan ibn ‘Atiyyah. Allah willing, they are included in what I had mentioned. Nonetheless, I agree with Ibn Battaal that it is possible to enumerate forty virtues of goodness, the highest in reward being the milch she-goat, and I agree with Ibn Al-Muneer in objecting to much of what Ibn Battaal had mentioned, which are apparently higher in reward than the milch she-goat.'"
Allah knows best.