Andy thinks he might take a job with a company that supplies private investigators and security for various functions for a much bigger salary than that of sheriff. The election for sheriff is coming up, and Andy encourages Barney to file for candidacy. Andy changes his mind after the deadline for filing has passed, and it looks like he might be out of luck.
Barney decides to organize a write-in campaign for Andy, because he thinks he'd be the better candidate. But Barney is dismayed to find that no campaign is necessary, because all of Mayberry tells him that they have heard about the situation and are voting for Andy. Barney's insecurity grows to the size of his pride so that complications ensue.
Don Knotts was so good at this role that, even today, most people know what it means when you point to somebody with a little authority that went to their head and say "That guy is a Barney Fife" even if they never watched this show. Nobody wants somebody like that in charge, so you can imagine how much a town with the original Barney Fife would not want him to be sheriff! Most people would prefer dealing with somebody like Andy Taylor, who'd rather talk his way to an understanding with people than read them the riot act, but I doubt it would work for long today, with people moving from place to place more and with much higher levels of violence.
Andy and Barney always worked as a comedy team because they were truly a contrast in styles.