It is narrated in Mustadrak al-Hakim and elsewhere that when Adam (peace be upon him) committed the mistake (he forgot and ate the fruit of the forbidden tree), Adam (peace be upon him) said: “O Allah! I ask You for the sake of Muhammad that You forgive me.” Allah the Almighty said: “How did you know him, when I have not yet created him?” Adam said: “When You made me with Your hand and breathed into me of Your spirit, I raised my head and saw written on the pillars of the Throne:
لا إله إلا لله محمد رسول الله
So I understood that the one whose name You have joined with Your own name is the dearest of all creation to You.”
Allah the Almighty said:
“O Adam! You have spoken the truth. Indeed he (Muhammad ﷺ) is the most beloved of all creation to Me. Supplicate to Me by means of him; I have indeed forgiven you, for had it not been for Muhammad ﷺ, I would never have created you.”
Investigation of the Hadith:
Shaykh al-Albani (may Allah have mercy on him) declared it mawdu’ (fabricated).
In his Talkhis of Mustadrak al-Hakim, Imam al-Dhahabi says:
بل موضوع Rather, this hadith has been fabricated.
The narrator Abd al-Rahman ibn Zayd ibn Aslam in it is da’if (weak).
And regarding Abdullah ibn Muslim al-Fihri, I do not know who he is.
All the hadith scholars agree on the weakness of Abd al-Rahman ibn Zayd ibn Aslam in it.
This narration is absolutely not sahih (authentic).