When does someone use AH-1Z Viper and when does someone use AH-64D Block III?
In terms of role, there is little difference between these two helicopters. Both are attack helicopters used for close combat and anti-armor. They area also capable of carrying almost similar weapons systems and combat commanders can use either of these for the same mission based on their availability(though this will depend on the compatibility of communication equipment)
Bell AH-1Z is development (albeit with significant upgrades) of Bell AH-1, the first attack helicopter of US army.
After AH-1, the US army decided on a dedicated attack helicopter (AH-1 was developed from UH-1 transport), which led to the AH-64 Apache.
AH-64D Block III Longbow is an advanced version of Apache with the Longbow fire control radar. It is under use by a number of countries apart from US Army.
The AH-1Z Viper, however, is used only by the USMC.