Madison Bumgarner matched zeros with Arizona starter Ian Kennedy into the eighth inning and the Giants pulled it out in the 11th when Schierholtz followed singles by Aubrey Huff and Buster Posey with his triple to center off Heilman (5-7).
Santiago Casilla (6-2) struck out the side in the 10th and Brian Wilson earned his 41st save to seal San Francisco's sixth victory in eight games. The Giants pulled within a half-game of first-place San Diego, which entered Monday night's game against the Los Angeles Dodgers on a 10-game losing streak.
Bumgarner was sharp, allowing five hits over 7 1-3 innings. Kennedy was even better, giving up two hits over eight innings.
Arizona right fielder Gerardo Parra kept the scoreless tie in tact in the ninth by diving forward to catch Posey's flare with two on and two outs, but Heilman was hit hard for the second straight outing.
The game included a couple of scary moments on consecutive at-bats in the fourth, when two children were injured by flying objects.
A 13-year-old boy sitting near the Diamondbacks dugout was put in a neck brace and carried off on a stretcher when he was struck on the right side of the head with a bat that flew from Posey's hands. Minutes later, a 2-year girl sitting in the upper deck was hit on the forehead by a foul ball off the bat of Pablo Sandoval.
Both were taken to the hospital as a precaution.
On the field, nobody could get to Kennedy or Bumgarner.
Kennedy was sharp for the fifth straight start, striking out six and retiring 14 of his final 15 batters.
The right-hander did a little work with his bat, too, leading off the eighth with his first career double. He was stranded at third after Javier Lopez struck out Kelly Johnson, and Ramon Ramirez got Chris Young on a fielder's choice to end the inning.
Bumgarner matched Kennedy almost pitch for pitch.
The left-hander struck out seven and twice got Adam LaRoche with two on and two outs: on a strikeout in the first inning and a fly ball to the warning track in right in the sixth.
Notes: Giants SS Juan Uribe didn't play after fouling a pitch off his left shin Sunday against the Dodgers. ... Arizona RF B.J. Upton missed his fifth straight game with a strained left shoulder. ... The Giants have won five straight road games.