When you arrive in country from overseas the immigration officer checks your passport.
In some countries you must have visa before you can enter.
Then you proceed to the baggage area to pick-up your bags and then to the customs officer who may,(but not always)check your baggage.