How to simulate heavy ion as incident particles?

I want to simulate a 500MeV Be9 beam. I have tried

G4IonTable::GetIonTable()->GetIon(4,9,0);

But it seems doesn’t work properly.
Is there any examples or instructions about this?

_Geant4 Version:_4.10.7
_Operating System:_ubuntu
Compiler/Version:
CMake Version:


That should be exactly right. However, you can only make that call after the RunManager has been initialized (e.g., the /run/initialize macro command). If you have your own PrimaryGeneratorAction, move that call to the GeneratePrimaries() function.