Thank you both for your responses.
The issue as suggested null was being returned by getVApps
Putting in place the supplied code is a workaround solution for this issue. With some further investigation getVapps was returning vAPPs that had already been deleted. Once the Organizations had been reloaded in Orchestrator we had no issues with Nulls.
Because our process is automated I do not want to worry about reloading in Orchestrator everytime a vapp is deleted. Is it possible to do a reload through code or is this a known issue
Again Thank you