Be persistent! Make sure the puppy doesn't get the opportunity to pee and poop by using a leash indoors or confining him to a crate when you're out. Depending on the puppies age, pop him outside every 20 - 30 minutes, so there's a greater chance of him toileting outside (by accident at first.) In addition, get rid of any scent markers he's left by peeing or pooping indoors, as these will draw him back to the same spot. This means cleaning the area daily, for 2- 3 weeks after he last pooped there to fully get rid of any lingering odor that the dog can detect.
There are a variety of established methods of animals training, each with its adherents and critics. Some of the better known dog training procedures include the Koehler method, clicker training, motivational training, electronic training, model-rival training, dominance-based training, and relationship-based training. The common characteristics of successful methods are knowing the animal's attributes and personality, accurate timing of reinforcement and/or punishment and consistent communication. The use of punishment is controversial with both the humaneness and effectiveness questioned by many behaviourists.
In one study laboratory-bred Beagles were divided into three groups. Group A received an electric shock when the dogs touched the prey (a rabbit dummy fixed to a motion device). Group H received a shock when they did not obey a previously trained recall command during hunting. Dogs in group R received the electric shock arbitrarily, i.e. the shock was administered unpredictably and out of context. Group A did not show a significant rise in salivary cortisol levels, while group R and group H did show a significant rise. This led to the conclusion that animals which were able to clearly associate the electric stimulus with their action, i.e. touching the prey, and consequently were able to predict and control the stressor, did not show considerable or persistent stress indicators, while animals that were not able to control the situation to avoid the shock did show significant stress.
It's not so much the dog doesn't listen, more that he doesn't understand what you want him to do. Go back to basics and don't punish him when he toilets indoors. Double your vigilance and take every opportunity to put him outside to toilet. The crucial thing is to be present when he does toilet in the correct place, so that you can reward him. This makes him keener to repeat the performance to get another treat. Conversely, if you have been telling him off for indoor accidents he may already feel inhibited about going to the toilet in your presence, including when he goes outdoors. This is one reason why it's important not to punish for inappropriate toileting.
A training class is not there to train your dog. Its purpose is to teach you to train your dog so you will need to be committed to train your dog for short sessions (5 minutes) several times a day rather than just simply turn up for classes! This little bit of training everyday will be repaid with a lifetime of living with a well behaved dog. You will also learn to avoid problems before they begin as well as receive help to overcome any that you already have with your dog.