The defense that something criminal, was in obedience to the law was rejected at Nuremberg, I think. Befehl ist Befehl, orders are orders, was used by various defendants, including Eichmann (in Israel). It was rejected normally, since individuals can still make moral choices, although at times, it has been allowed, for example, under duress.
"The fact that a person acted pursuant to order of his Government or of a superior does not relieve him from responsibility under international law, provided a moral choice was in fact possible to him."
The classic case in WWII was the execution of prisoners, which some German officers justified as direct orders from Hitler, but some of them were still executed after the war.