Walls and fences are effective in reducing encroachment, which is why they have been used from antiquity through today. They continue to be widely used around military bases, airports, schools, high-end homes, the Vatican, Israel, secure storage locations, power plants, electrical substations, water-treatment plants, construction areas, pools, parking areas, ports, and so on.
Of course a wall isn't going to stop 100% of people. Window screens don't keep out 100% of insects. Sunscreen doesn't block out 100% of UV. Medicine doesn't have a 100% cure rate. They are still useful.
Hungary is an example.
In 2015, there was the Migrant Crisis in Europe (
https://www.bbc.com/news/world-europe-34131911 ).
Illegal immigration into Hungary went to over 300,000 per year (mostly through Serbian border).
They put up a fence along the border with Serbia.
Here is a chart of number of illegal immigrants per day, reported by Hungary across the time of completion of the project.