First, to make sure that we are talking about the same thing, let me make clear that my answer pertains to a scenario in which the entire class failed after making a sincere, good faith effort to study and do as well as possible on the exam. (If you are talking about something else, like students conspiring with each other to all fail the exam as a form of protest of the bad quality of teaching or because they believe it is pointless to even try to study for it, my answer would be very different.)
Now that we got that clarification out of the way: if all the students failed, that would certainly be a very clear warning sign to the professor and department that something has gone seriously wrong with the course. What I would recommend in that case is for the students to document their grievances in a very clear way, including any relevant evidence, and take the matter up with the department chair or head or other appropriate university authority. Assuming that you are in a reputable department at a reputable university, what I expect to happen is that the department will initiate some kind of external review of what took place by people other than your professor. Assuming that your claims are found to be reasonable, I believe the department will be strongly motivated to take steps to address the situation in a way that repairs at least some of the harm that was done to the students. This could be in the form of a change to some or all of the grades, or, if it turns out the grades are essentially meaningless and no useful information can be salvaged from them, some other creative solution.
If the department is unwilling to address your complaints, you can try to enlist the help of your student union, go to other university authorities (e.g., dean, grade appeal committee, ombuds office), and, if else fails, even try to use social media to create a scandal and rally support for your cause. However, if you really have a strong case with good evidence that you have been mistreated, I doubt that will be necessary, since no sensible department will want to risk having its reputation tarnished by mistreating its students in a blatantly unfair way.
Finally, let me add that in my opinion the right thing for you to do right now is to concentrate on studying for the exam and not worry too much about emailing the professor with your concerns or about what will happen in the aftermath. It may turn out that your concerns were unwarranted and a good number of students end up doing just fine, so all this energy that you are spending right now on worrying would have been better spent on studying. Good luck!