Flex is not really the issue here.
It is recognising and catching invalid numbers for a particular aircraft weight and takeoff condition (thrust and performance) when distracted, tired, rushed and/or constrained to complex SOPs and patter.
It is how to catch these numbers before using them kills you and your passengers.
On Flex - a technique that I was taught and like was to 'Flex' only to no less than 2000' of the available runway length, intersection or full - an extra safety margin adopted by many operators of my type.
A takeoff in conditions that required any greater amount of the runway than that required full takeoff thrust.
On top of normal V speeds, knowing that you should be at 35' by 2000' to run and seeing that point approaching quickly is a recognisable point at which to apply TOGA if less was leaving you under-performing.
It would seem reasonable to me to only flex in a heavy to within 4000' of runway available.