Age of Information (AoI) and delay are crucial performance metrics for Industrial Internet of Things (IIoT) applications not only to perform seamless actuation and control actions but also to enable self-organized and re-configurable manufacturing systems. A challenging task in heterogeneous IIoT networks is to minimize the AoI while maintaining a predefined delay constraint. In this work, we consider a Device-to-Device (D2D)-based heterogeneous IIoT network that supports two types of traffic flows, namely AoI-sensitive flow and delay-sensitive flow. First, we introduce a distributed backlog-aware random access protocol that allows the AoI-sensitive nodes to opportunistically access the channel based on the queue occupancy of the delay-sensitive node. Then, we develop an analytical framework to evaluate the average delay and the average AoI, and formulate an optimization problem to minimize the AoI under a given delay constraint. Finally, we provide numerical results to demonstrate the impact of different network parameters on the performance in terms of the average delay and the average AoI. We also give numerical solutions of the optimal parameters that minimize the AoI subject to a defined delay constraint.