Joseph tells his brothers about a dream he had in which his brothers’ sheaves of wheat bowed to his sheaf. This makes them hate him more than they already do. Then he tells his brothers and father about a dream he had in which the sun, moon, and eleven stars bowed to him. This makes his brothers jealous and is of concern to his father. His brothers plot to kill him, then after they decide not to do that they throw him into a pit and he is sold to some Ishmaelite merchants on their way to Egypt, who transport him on the back of a camel along with their other goods (they lie and tell Jacob that Jospeh was killed by wild animals). Later, Joseph’s brother Judah engages the services of a veiled prostitute sitting by the entrance to Enaim. He doesn’t know that the prostitute is his widowed daughter-in-law Tamar*. Meanwhile in Egypt, Joseph has been purchased by Potiphar, courtier of the Pharaoh. He has risen to a high position in the household due to his excellent service. While Potiphar is away, Potiphar’s wife tries to seduce Joseph. Joseph flees as Potiphar’s wife grabs at his garment.
*Context: Upon the deaths of her previous husbands Er and Onan (Judah's sons), Judah had not allowed Tamar to do what was culturally expected and marry his other son Shelah (because he suspected a connection between Tamar and the deaths of the other two sons). This left Tamar with no place in society. Tamar knew Judah would be at Enaim and went there with her veil on, in order to initiate the carnal transaction, in protest of the impossible circumstance she found herself in. Later, Judah hears that Tamar has been working as a prostitute, and is pregnant. He orders her to be burned alive. As she's being taken out to receive this punishment, she reveals that she was the prostitute Judah went to bed with at Enaim, and that the children she is carrying are Judah's. On learning of this, he acknowledges that he was more in the wrong than she was since he did not allow her to remarry. (You'd think that insight could already have occurred to him when all he knew was that Tamar had worked as a prostitute, but it seems that the ideas is, he understands that her act was intended to send him a message, she's not really a prostitute but a family member acting out in an unjust situation. Or maybe Judah realizes that, while the hypocrisy of punishing a relative for prostitution when you are a client of prostitutes is one thing, it's even more extreme when you were the client in the transaction for which you have pronounced punishment.) We are not told that the execution order was rescinded but apparently it was since Tamar goes on to give birth to twins conceived in her union with Judah.