We consider the minimal action problem min \int\_R 1/2 |$\gamma$'|^2 + W($\gamma$) dt among curves lying in a non-locally-compact metric space and connecting two given zeros of W $\ge$ 0. For this problem, the optimal curves are usually called heteroclinic connections. We reduce it, following a standard method, to a geodesic problem of the form min \int\_0^1 K($\gamma$)|$\gamma$'| dt with K = (2W)^(1/2). We then prove existence of curves minimizing this new action under some suitable compactness assumptions on K, which are minimal. The method allows to solve some PDE problems in unbounded domains, in particular in two variables x, y, when y = t and when the metric space is an L^2 space in the first variable x, and the potential W includes a Dirichlet energy in the same variable. We then apply this technique to the problem of connecting, in a functional space, two different heteroclinic connections between two points of the Euclidean space, as it was previously studied by Alama-Bronsard-Gui and by Schatzman more than fifteen years ago. With a very different technique, we are able to recover the same results, and to weaken some assumptions.