In the book, Beit Aharon, compiled by Rabbi Aharon of Karlin, there is an interpretation of the opening verse in Psalms 111, “Praise God! I thank God with all my heart, in the counsel of the upright and in the congregation,” referring there to three different levels of prayer. “If a person can pray ‘with all his heart,’ that is well and good. But if, God forbid, he cannot, then he should at least pray ‘in the counsel of the upright,’ meaning through his relationship with a tzadik, a righteous person. But if prayer at even that level is not possible, then he should at least pray ‘in the congregation;’ through his connection to the Jewish people.” These three levels correspond to the righteous, the intermediate and to the wicked. Let us explain
The righteous person, one who has refined his ego and uses it only for positive pursuits, can pray and serve God by his own initiative, with all his heart, i.e. with both his good inclination and with his evil inclination.
The person on a spiritually intermediate level (called a beinoni in the Tanya) recognizes the fact that his heart is not yet completely refined and prays through the power of his connection to the righteous individuals, the heads of the Jewish people. In comparison to the righteous individuals, this person feels himself like a toenail of the Jewish people (perhaps even an ingrown toenail or one that has a fungal infection…).
But, the wicked person does not even harbor a proper connection with the righteous people of the generation; nonetheless, he can approach God in prayer by feeling how he is a part of the Jewish people as a whole. This type of prayer can be compared to the incense offering, which was permitted only if it contained the foul-smelling galbanum amongst the other pleasantly aromatic spices. Similarly, in the latter case, the prayer of the wicked person is accepted because it is an integral part of the prayers of the entire Jewish nation.
Let’s try to understand this idea more deeply. How can we say that only the wicked should be the ones to pray through their connection with the Jewish nation as a whole and as a very last resort when all else fails, when in fact, every one of us is supposed to perform every commandment “on behalf of the Jewish nation?” The answer to this question is that these three levels are actually three cumulative states that build upon one another.
Connecting to the entire Jewish nation is the fundamental state of the soul, which obviously is not absent in the intermediate individual or in the righteous person. Rather, the wicked person is focused on this state as a primary foundation on which he can base his service of God. The intermediate person should have already internalized his connection with the Jewish nation as a whole as a basic precept and should consciously be working on his spiritual connection to the tzadikim, the righteous heads of the Jewish nation, feeling how small and insignificant he is compared to them. The tzadik himself has accentuated his connection to the entire Jewish people to such an extent that the connection has become an integral part of his being and he prays to God with all his heart not merely as a matter of “counsel” but as a part of his nature.
This brings us to the interpretation the Sfat Emet offers on this verse. "'I thank God with all my heart,’ meaning that when King David, of blessed memory, said his psalms, he captured all the hearts of the Children of Israel … which resulted in the arousal of the heart of every Jewish person… for King David had no personal interests and through this selflessness before God he had the power to arouse the hearts of the Jewish people.”
This teaches us that the truly righteous person identifies so closely with the soul of the Jewish people as a whole that all of his service acts automatically on their behalf, through his absolute selflessness. In fact, his expression of gratitude—"I thank God with all my heart"—is a sign of his profound acknowledgment of God and his selflessness before Him. This is the personal service of the righteous person in which his heart arouses the heart of the entire Jewish nation. As Maimonides states, “[The king’s] heart is the heart of the entire people of Israel” (Hilchot melachim 3:6).