In the beginning, he understood. As he built the House of God, ha was acting FOR god. And he realized that the task of coming before God wasn't the building, nor the sacrifices therein.
1Ki 8:37 When there is famine in the land; when there is pestilence, blasting, mildew, locusts; when there is the stripping locust; when its enemy has distressed it in the land in its gates; any plague, any sickness,
1Ki 8:38 any prayer, any supplication that shall come from any man of all of Your people Israel, who shall each know the plague of his own heart, and shall spread his hands toward this house,
1Ki 8:39 then You shall hear in Heaven Your dwelling place and shall forgive and shall act, and shall give to each according to all his ways, whose heart You know (for You have known, You alone, the heart of all the sons of Adam)...
But there is a limitation to this thing he asked of God at the beginning- human wisdom. While Elisha asked for a double-portion of the spirit of God, which removed all doubt, Solomon asked for wisdom. But wisdom caused him to seek after logical conclusions. He pushed the envelope, marrying all those wives in an effort to find that which was not vain; building until his people were at the breaking point, hoping to find an answer in accomplishment and legacy that he wasn't finding in pleasure; studying life through the eyes of knowledge to find a reason, only to say at the end:
Ecc 7:16 Do not be too much righteous, nor make yourself overly wise; why destroy yourself?
For he had done all these things. He had tried hard work; he had tried pleasure; he had looked into good and evil, wisdom and foolishness, and at the end of it, realized that all his wisdom had accomplished nothing. Nothing that meant anything. He should have been happy with each day's gifts. He should have sought love and not pleasure. He should have done his best at each day's work. But the thing he found that was most important- he should have used that wisdom, not on the things of this world to simply obey God...
Ecc 12:12 And more than these, my son, be warned: The making of many books has no end, and much study is the weariness of the flesh.
Ecc 12:13 Let us hear the conclusion of the whole matter: Fear God, and keep His commandments; for this applies to every man.
Ecc 12:14 For God shall bring every work into judgment, with all that is hidden, whether it is good, or whether it is evil.
So the lesson of Solomon is to go back to the beginning, when he understood without TRYING to understand. When he realized that each of us has to come to grips with "the plague in our own heart", and bring it to God. None of his wisdom or greatness ever brought him closer to God than THAT moment.