heparin is used because it acts immediately. Warfarin might be given, but it takes a day or two to begin working.
But heparin is given by injection or instead usually by IV, so it's not practical except when the patient is in the hospital. Warfarin is oral.
IV is better because the dose that is delivered to the bloodstream is more sure. Injecting heparin into the body can results in variable dosing, depending on the nature of where the heparin is injected (e.g. a fat person vs a thin person).
Heparin is an anticoagulant, so it helps to dissolve the clot. It does that by inhibiting clot formation, while the natural clot dissolving chemicals like plasmin act on the clot. Heparin does not actually dissolve anything.
Low molecular weight heparin is more advanced, and then synthetic kinds are even more advanced.
The biggest risk is that of bleeding, as Ken says. Another is heparin induced thrombocytopenia (HIT), where an autoimmune response kills the platelets.
As an anti-coagulant, herarin can help prevent strokes from a blood clot. Clots can form in the heart, veins and lungs and carried to the brain. The risk is excessive bleeding. It certainly would be contraindicated if there is a history of bleeding.