Magnetically mediated superconductivity in heavy fermion compounds