{1}{R}, {T}: This creature deals X damage to any target and X damage to itself, where X is the number of Elemental cards in your graveyard.
If Sunflare Shaman leaves the battlefield before its ability resolves, it will still deal damage to the target. If Sunflare Shaman is put into your graveyard, it even counts toward the amount of damage dealt.
If the target leaves the battlefield or otherwise becomes an illegal target before the ability resolves, the ability doesn't resolve and Sunflare Shaman won't deal any damage to itself.