Once the required information is extracted from the incoming email, additional Apex code handles the next task of reading the Position record for the job application being processed. The SOQL query for the record retrieval is wrapped within a try/catch block to handle the circumstance where the Position record is not found. If the Position record is not located, the resulting DmlException is caught and a new exception is thrown with text explaining the issue to the user.
// Resolve the Id of the Position they are applying for Id positionId; try { // Lookup the Position they are applying for by name Position__c position = [select Id from Position__c where name = :positionName limit 1]; positionId = position.Id; } catch (Exception e) { // Record not found throw new ProcessApplicantException( 'Sorry the position ' + positionName + ' does not currently exist.'), }
3.15.18.61