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 baggae area ti pick-up your bags and then to the customs officer who may,(but not always)check your baggage.