I thought for one to receive salvation one has to receive the sacraments of the church?
You thought wrong. God created the sacraments for our salvation. But God is not limited by his creation.
The Council of Trent confirmed that baptism,
OR ITS DESIRE, remits all sin. St. Thomas Aquinas taught that invincible ignorance removes the voluntary nature of an act, and as such, a material sin committed due to this kind of ignorance cannot be a formal sin. Moreover, vincible ignorance may diminish the voluntary character, but does not remove it, and as such, sins due to vincible ignorance can be formal sins. Yet, to be a mortal sin, full advertence and perfect consent of will is necessary, according to St. Pius X, which sins of vincible ignorance necessarily lack. St. Pius X taught that people that live in “good faith,” although objectively heretical,
may be “on the way of salvation” (in a way known only to God.) St. Pius X called these separated in body from the Catholic Church, but united in soul. Vatican II didn’t change this, but it did reaffirm it.
The Joint Declaration on Justification affirms that condemnations of the Council of Trent remain in effect. What some Protestants
mean when they affirm justification by faith alone seems to indicate that they affirm that justifying faith includes hope and charity. Thus, some versions of faith alone can be reconciled with Catholic theology, if “faith alone” is effectively understood to mean “justification by faith, hope, and charity.”
You can read a discussion regarding the Joint Declaration on Justification here:
Are we justified by faith alone?