If you set your heater to 30 C (86 F) and the tank is really 40 C (104 F), then here's something to try.
1) Put a thermometer in the water and get the exact temperature. Let's call it X degrees. (X is whatever the thermometer says, so 40 C, or 38 C or whatever it really says is what we mean by X.) That's the "official" temperature.
2) Next, confirm the heater knows when to come and off. Set the heater in the tank to 2 degrees C over X. (If X was 40, make the heater set to 42.) Does the heater in the tank come on?
Set if for 2 degrees under X. Does it go off?
If the heater does those things correctly, it's not defective. That means when it was set to 30 C, it was likely not coming on above 30 C.
If it fails either test, the heater is defective and needs to be replaced.
3) If the heater is not defective, something else is heating your tank, not the heater.
For example, the room is 40 C degrees and makes the tank 40 C. Or the room is well over 30 C and you have a large pump and a UV filter adding heat causing the tank to be 40 C.
Or your tank is getting direct sunlight all day and combined with the room temperature and things inside the tank, it ends up going up to 40 C.
It's not unusual to have a broken heater. It will likely be the problem. But a very warm room with a pump can get pretty hot as well.
One year, it got up to 115 outside and it was 93 inside my house. Yow!! It's hard to keep a tank under 100 in that situation.