Rashi, citing the Medrash, explains that the Torah juxtaposes the story of Potiphar’s wife with the story of Tamar and Yehuda to show that both women were acting לשם שמים -- for the sake of Heaven.
Tamar yearned to mother the royal House of Judah. Seeing she was rejected, she took the unconventional approach of consorting, incognito, with Yehuda and gave birth to Peretz as a result. Among her descendants were Boaz; and David, forerunner of Moshiach, may he come speedily in our days.
Potiphar’s wife also had good intentions. Gazing in her crystal ball, she saw her destiny intertwined with Yosef’s. Somehow, she would unite with him and start an illustrious lineage that would culminate with Moshiach ben Yosef! Unfortunately, she could not see clearly and wasn’t sure if it would be her or her daughter. Yosef did ultimately marry Potiphar's daughter and fulfill her vision.
So we should really start asking ourselves: How do I know if my intentions are לשם שמים or "wishful thinking"?
The real indicator is: What happens when things don’t go the way we planned.
Look what Tamar did when she was almost taken to burn at the stake! She kept quiet and put her life in Yehuda's hands rather than publicly humiliate him, trusting Hashem that Yehuda would choose to save her.
The wife of Potiphar had a very different strategy. When her plan did not go as she had hoped, she lied, pointed her finger at Yosef and had him thrown into the dungeon. Not only was she unwilling to take the blame, she shifted it to Yosef instead!
When Rav Chaim of Volozhin developed his vision for an organized Yeshiva network system, he approached his Rebbe, the Gaon of Vilna. He presented his plan with great enthusiasm. To Rav Chaim's bewilderment, his Rebbe was unimpressed and dismissed the idea out of hand. He continued to approach the Gaon on several occasions, receiving a lukewarm response each time. Deflated, Rav Chaim decided to give it one last try. He quietly laid out his plan before his Rebbe, expecting the worst. This time, the Gaon gladly gave his complete and unqualified blessing.
"Why is this time different than all the other times?", asked Rav Chaim. The Gaon explained that the previous times, you were so excited, I was afraid it was just a fleeting dream, tinged with visions of fame and grandeur. I needed to bring you back down to earth, and diffuse your external enthusiasm to make sure that you truly have the Honor of Hashem in mind. Only if we truly have pure intentions will our efforts be sure to succeed!
In our own small way, let us try to do something completely for the sake of Heaven. Perhaps it can be an act of kindness that nobody knows about. Perhaps we can improve ourselves in some way without any fanfare or recognition. And may Hashem bless our deeds as well and bring Moshiach speedily in our day!
Have a wonderful Shabbos!