Your capacity for self-control is similar to the muscles in your body. Like biceps or quads, willpower can vary in its strength. Not only from person to person, but from moment to moment. Just as well-developed muscles sometimes get tired and feel like jello after a strenuous workout, so too does your willpower "muscle."
Even everyday actions like decision making or trying to make a good impression can sap this valuable resource. The coping with the stresses of your career and family can sap you of your energy. When you tax it too much at once, or for too long, the well of self-control strength runs dry. It is in these moments that the doughnut or cake wins.
So the first thing you are going to want to do, if you are serious about resisting temptation, is make peace with the fact that your willpower is limited. It is not an endless resource. If you've spent all your self-control handling stresses at work, you will not have much left at the end of the day for sticking to your goals.
Check out the new video on why I believe Willpower Isn't Enough.