Changed Java Code to Apex