lean on me when you need a friend or
whenever you need me, i will be there
also your sentence is correct, i think what you mean is; i will be there when you need me, i understand what you mean, and it is correct
you can use it with a good friend that you like and trust