So reoccurring questions keep coming up about magic. Yes, it can be a bit unclear because it is so erratic compared to other parts of the Action Phase. I have tried to boil down a few general guidelines about the spells so that it might be a little more clear.
Spells that are destructive (meaning they cause harm to the enemy) will usually be harmful to you as well if you're in melee combat with the unit. You should randomize the effects of the spell between you or the target. Usually the risk of hitting your own models is not worth it so you may need to plan well when things should take place in the Action Phase. 'Remain in play' spells do not need to continue being randomized after they have been cast. Randomize the effects only when the spell is first cast.
Now for a related item, spells that help you are only applied to your models (even if they are in melee with an enemy).
Most spells cannot target commanders in a unit (just like shooting). However, lone commanders are fair game (as long as the spell is not a 'large target' spell). Friendly magic users may cast any spell as they wish on a commander in a unit as long as line-of-sight and other rules are followed.
When a spell causes a damage value, Damage Resistance in usually negated as if the spell damage was a single hit (one model's Damage Resistance) before removing Life/models.