Almighty Allah revealed: And to David We gave Solomon. How excellent a slave! Verily, he was ever oft-returning in repentance (to Us)!
When there were displayed before him, in the afternoon, well trained horses of the highest breed (for jihad in Allah's cause). And he said: 'Alas! I did love the good (these horses) instead of remembering my Lord (in my Asr prayer)" till the time was over, and (the sun) had hidden in the veil (of night). Then he said: "Bring them (horses) back to me." Then he began to pass his hand over their legs and their necks till the end of the display.
And, indeed We did try Solomon and We placed on his throne Jasadan (a devil, so he lost his kingdom for a while) but he did return (to his throne and kingdom by the Grace of Allah and he did return) to Allah with obedience and in repentance. He said: 'My Lord.' Forgive me, and bestow upon me a kingdom such as shall not belong to any other after me: verily, You are the Bestower."
So, We subjected to him the wind, it blew gently to his order whither-so-ever he willed - and also the devils from the jinns (including) every kind of builder and diver, - and also others bound in fetters. (Saying of Allah to Solomon): 'This is Our gift, so spend you or withhold, no account will be asked." And verily, he enjoyed a near access to Us, and a good final return (Paradise). Surah 38: 30-40