Only if the berries will actually be consumed by someone other than you for hp restoration in the future, and then only once at the time of casting
Let's break this down:
Say we have the situation in the question. You're a Life domain Cleric, you've cast goodberry. Someone else eats one. "Aha!", you think, "Now I shall heal me some hit points!". Alas, it is not to be so. The ability states:
When you cast a spell
So clearly you don't the hit points now. "Oh, well did I get them then, then?", you might respond. And the answer is yes!
If we look now, when someone has been healed, at your casting of goodberry, it's clear that you met the requirements for your class feature to trigger: you cast a spell of 1st level or higher, that spell healed hp to another character, and so you should have reaped the healing benefits accorded to you by that feature.
But what if you cast the spell and the berries get lost or you eat them all or something? Well, that case is equally clear! You didn't heal hp to another creature, so you don't get any hp yourself.
Ultimately, what this comes down to is that the behavior of the class feature at the time of casting depends on triggering conditions that can only happen in the future.
That means that when we cast the spell, we are retrocausally healed or not healed by the future use of the berries. Most other methods of determining the result of future outcomes contain this clause:
The spell doesn't take into account any possible circumstances that might change the outcome, such as the casting of additional Spells or the loss or gain of a companion.
Your GM may or may not decide to apply this common clause to this particular call for retrocausal outcome prediction.