Camera to view all

In my space 3d I insert, with a click on a button, a cube one on top of the other.
When the cubes become many I no longer see all the cubes.

Question:
How change/resize my camera to view always all cubes?

this thread could be help.

This is relatively easy with an OrthographicCamera but Hard to get a tight fitting view with a perspective camera.