There's only so much that can be done to avoid rejection, especially in a subjective industry like publishing. There are as many reasons to reject a work as there are agents or editors working (probably more). You really can't control the fact that your work will likely be rejected at some point, unless your best friend/mom is the owner of a major publishing house. What you can control is how you react to it. So, let's talk about handling query rejection for a bit (much of the same advice can be applied to not getting into contest or getting rejected by an editor).
If I go ahead and assume that your query was addressed to the right person, talked about a completed work within acceptable word count limits, and demonstrated a reasonable grasp of the language in which you'd like to publish it, the rejection probably is not a reflection of you personally (even if you made a mistake and addressed it to the wrong agent - which I've also done - it doesn't make you a bad human being).
I've been very surprised at some of the things I've seen:
- Trashing the agent in online forums. (Especially with your name or identifying information!)
- Posting on Twitter about how rude a rejection letter is. (Honestly, unless it said "You suck," it probably wasn't actually rude. It just may not have been what we all want to get.)
- Responding to call the agent an idiot.
- Attacking the agent on the street (Yes, this happened, and it's horrible. Don't be that person.)
But vent about it privately, to friends or relatives. Don't post it online. You don't want to find an agent who loves your work - but passes because of something you posted out of anger or frustration. Better ways to deal with rejection:
- Take a bubble bath.
- Go for a run/walk/swim/Zumba... whatever works for you.
- Eat some ice cream.
- Binge watch Dawson's Creek.
- All of the above.