High-side switch with BJT for 24V controlled by logic level
simulate this circuit &ndash; Schematic created using CircuitLab

*Figure 1. Switch driven by 5 V squarewave. Solenoid represented by 1 µH inductor (in the absence of any other information) with 390 Ω (1.5 W) resistance. *



Figure 2. The CircuitLab simulation results.

It looks OK to me. If you have problems then measure the voltages at various points and add them into your schematic using the NODE circuit element.