It’s true that a lot of excellent work gets rejected by agents and editors.
Perhaps they don’t think it’s commercial enough; perhaps the story is good but the writing isn’t, or vice versa. Perhaps it hasn’t been submitted to the right agents, editors or imprints. Perhaps it’s too similar to something else that has already been published. There could be all sorts of reasons why good writing gets rejected. But if it’s good enough then it’s almost certainly going to be published eventually, so long as the writer (or his or her agent) persists.
Most of the work that gets rejected doesn’t fit into this category. Most is of vastly inferior quality, which is why it gets rejected. What few people appreciate is just how truly awful most of the slush-pile is: I don’t mean that it’s awful in that it needs a little tidying up, or a bit of an edit: it’s awful in that the bulk of it is incomprehensible and unreadable.
To paraphrase James D Macdonald: if you can write something that’s grammatically correct, which doesn’t contradict itself too many times and which shows a reasonable understanding of both spelling and punctuation then you’re already in the top ten per cent of the slush-pile, with a good-to-excellent chance of getting read—and getting published.