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.

Artwork
Loading artwork…
Sunflare Shaman
Morningtide · #108 · EN
Nonfoil—Foil—
Card rules
1
,
: This creature deals X damage to any target and X damage to itself, where X is the number of Elemental cards in your graveyard.
2/1
A spark to light the guttered heart.
Common · Illustrated by Dave Dorman
Format legality
Commander Legal
Duel Legal
Legacy Legal
Modern Legal
Oathbreaker Legal
Pauper Legal
Pauper Commander Legal
Penny Legal
PreDH Legal
Tlr Legal
Vintage Legal
Alchemy Not Legal
Brawl Not Legal
Competitive Brawl Not Legal
Future Not Legal
Gladiator Not Legal
Historic Not Legal
Old School Not Legal
Pioneer Not Legal
Premodern Not Legal
Standard Not Legal
Standard Brawl Not Legal
Timeless Not Legal
Rulings
Published rulings from the downloaded Scryfall catalog. Source card record · Rules and interactions
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.