I'm going to try to answer this despite your lack of detail. As I said in the comment area, this answer varies significantly depending on which format of Pokemon you're playing, and also according to which Salamence variant you are concerned about. Defensive Salamence and offensive Salamence have completely different purposes, and are beaten in different ways as a result. For simplicity's sake though, I'll look specifically at the most common Salamence variants found in standard Wifi or OU (before it was banned from OU of course). If you're looking for Ubers, Lugia is the most consistent "counter" to Salamence.
Entry hazards are a significant part of competitive play, and Stealth Rock is arguably the most influential of them all. This is due to its ability to remove a significant chunk of health from any Pokemon that is weak to Rock upon switch-in, and Salamence happens to be one of these Pokemon. Losing 25% of health each time it switches in is a major problem for Salamence, and is one of the reasons why it runs Roost on all of its sets. The move can help significantly in allowing your Pokemon to land a hit that can beat Salamence in one hit. For example, Mega Metagross can get a guaranteed OHKO on physically defensive Salamence (running 248 / 136) with Ice Punch, something it had a minuscule chance of doing without Stealth Rock.
Without Stealth Rock, landing a hit that can OHKO Salamence becomes very difficult, especially without a decent Ice move. Stealth Rock softens it up significantly and makes revenge killing it much easier.
Choice Scarf and fast Pokemon
Choice Scarf is probably one of your most reliable ways of revenge killing Salamence, but only works if Salamence hasn't reached +1 Speed. If your Choice Scarf Pokemon has more than base 120 Speed, it can revenge kill +1 Salamence with 252 investment, but any lower and Salamence will move before you.
Being able to move before Salamence is a great way to beat it. Its base 120 Speed and many opportunities to use Dragon Dance mean it will generally be first to attack. However, if you can move before it does thanks to the extra speed from Choice Scarf, you can land a hit on it that may be able to OHKO it, or at least weaken it so that it can't switch into Stealth Rock again. Some speedy Pokemon that have more than base 120 Speed can move before Salamence given that it isn't at +1. Weavile is a good example of this - its Icicle Crash attack can OHKO any variant of Salamence from full health. Priority is another way to beat Salamence, specifically Ice Shard which Salamence has a 4x weakness to. Offensive Salamence is OHKO'd by the attack after Stealth Rock if used by Mamoswine or Weavile (for example), and defensive Salamence doesn't fare much better.
Other means of priority such as Choice Band Talonflame's Brave Bird or Bisharp's Sucker Punch can leave a dent in Salamence, or potentially knock it out if it is weakened.
Klefki is by no means a counter to Salamence as it is cleanly 2HKO'd by Earthquake and will be OHKO'd if it has taken a bit of chip damage as well. (Besides, there's basically nothing that can efficiently counter every Salamence variant.) However, thanks to Prankster and Thunder Wave, it is capable of crippling Salamence regardless of how many boosts it gains. Thunder Wave will make Salamence extremely slow and give it a chance of being unable to move, which will end its sweep assuming you have a Pokemon capable of taking it down now that it is paralysed. Klefki's Play Rough attack is actually capable of getting a 2HKO on Salamence after Stealth Rock, but only if it is running an offensive set.
Klefki works even more effectively if you're playing Wifi, as its Swagger move is not banned in the format unlike in OU. Swagger will work nicely with Thunder Wave, giving Salamence an even worse chance of being able to move. It will also hit itself in confusion for much more damage due to the Attack boost that Swagger gives it. Be careful with this move, however. If Salamence breaks through and you aren't able to paralyse it before it takes you down, you may end up boosting its sweep. For this reason, you should only use Swagger if it has been paralysed first.
Klefki could be considered a "counter" to Mega Salamence if it doesn't run Earthquake or Fire Blast, as it walls its other attacks. Klefki is also a solid way to stop defensive Salamence, as it is immune to Dragon Tail so it can't be phased.
Fairy-types are only reliable ways to take down Salamence if it is using a defensive set, as Return or Double-Edge from an offensive set will leave a massive dent in them if they don't pack a resistant secondary typing. However, as defensive sets don't run much Attack (if at all) and usually only carry Body Slam, Fairy-types can fight defensive Salamence quite easily, walling Dragon Tail and hitting it for decent damage with Moonblast, Play Rough, Pixilate Hyper Voice, etc
Intimidate is a useful way to lower Salamence's attack, greatly decreasing its power and removing a boost if it has used Dragon Dance. Pokemon like defensive Landorus-T which carry Intimidate can switch in on Salamence and eat up its attack. Stone Edge from defensive Landorus-T can 2HKO Salamence if it has taken Stealth Rock damage. Intimidate also means that there'll be lots more Pokemon on your team that can take a hit from Salamence and potentially KO it back.
Status and chip damage
Let's not forget burning Salamence as a way to decrease its attacking power. Burning Salamence can shut it down for the entire game, and gradually weaken it as well. Poisoning it can also also wear it down, and potentially end its sweep if you stall around and let the damage build up. Chip damage from weather, Rocky Helmet, Leech Seed, etc. can also help wear down Salamence.
Pokemon like defensive Rotom-W can take a hit and burn Salamence, and Pokemon like Ferrothorn can annoy offensive variants if they don't carry Fire Blast, thanks to Leech Seed, Iron Barbs, status, etc.
Overall, countering Mega Salmence is very much a team effort. Due to its sheer power, speed and bulk, it's unlikely that you won't lose a team member to it before getting it into a position where you can beat it, and you'll likely need multiple Pokemon contributing something to take it down. Salamence's lack of any actual counters makes it a fantastic win condition - sometimes there's literally nothing you can do to beat it. For this reason, taking it down early a good way to prevent a late game Salamence sweep.