No, trenches and foxholes do not work effectively to counter artillery in CM.
For a very specific reason: In CM, you need to manually order your guys to take cover (HIDE) in the foxholes, or they won't protect from artillery. Your troops can "cower", but this does not activate the foxhole arty protection.
The HIDE command can only be given once every minute. In real life, the captain doesn't need to walk down the front line shouting at his men to take cover from mortars. They would do that by themselves and react on a second to second basis.
Adding to this problem is that in CM, while troops are actively hiding in the foxhole, they can almost not fight at all. Whereas in real life, you'd be able to shoot back reasonably well while most of your body would be protected.
Also, for some reason the enemy are able to spot and shoot troops hiding in the bottom of foxholes from a distance of about 70 metres or so. In real life, you'd need to get closer and use hand grenades or flamethrowers.