One rich man who thought righteousness, or living eternally in the kingdom of God, was achieved through obedience to the Ten Commandments asked... Jesus what he needed to do to gain eternal life (Luke 18:18).
Jesus, knowing his heart, told him to keep the commandments of God.
The man replied he had kept the commandments since he was a child.
Then Jesus told him to go sell all he had, give to the poor, and follow him, then he would have eternal life.
Jesus' disciples asked him how could anyone gain eternal life if this man could not, since this man had obeyed the law from childhood.