This is because you declare this inside if block. SO its scope is limited to if block and you are trying to access it outside if so declare it outside of if block Case incomingCase = new Case(); if(toAddresses.size()>0){