You need to sign in to do that
Don't have an account?
Patrick Hanahan
Error: Compile Error: Non-void method might not return a value or might have statement after a return statement. at line 36 column 1
This is the error I'm getting on this code. The error is for the last for loop. I thought I knew what the error was saying, but the wording is kind if confusing, and everything I've tried hasn't fixed it. Any ideas?
global class ParseEmailSubjectForJobNumber implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.Inboundenvelope envelope) { Account account; Messaging.InboundEmailResult result = new Messaging.InboundEmailResult(); try { // Creating Regex to base pattern on and pulling email subject into a string String jobNum; integer cancelled = 0; Opportunity opportunity; String regex = '\\b\\d{7}\\b'; String subjectSentence = email.subject; // Splitting the email subject into a list of words and removing all "(" and ")" and "J" // to make the regex simpler List<String> subjectSplit = subjectSentence.split('\\s+'); for (String input : subjectSplit){ input = input.replaceAll('(', ''); input = input.replaceAll(')', ''); input = input.replaceAll('J', ''); } Pattern p = Pattern.compile(regex); // checks for the word cancelled in the subject, and sets the variable "cancelled" to 1 if it finds it (the variable is for later use) for (String input : subjectSplit){ if (input == 'cancelled' || input == 'Cancelled') cancelled = 1; } // loops through all words in the subject to find the job number, then sets the opportunity with the corresponding // job number to cancelled if the subject also contains the word cancelled for (String input : subjectSplit){ Matcher m = p.matcher(input); if (m.find()){ jobNum = input; if ([select count() from Opportunity where Job__c = :input] != 0 && cancelled == 1){ opportunity = [select Id from Opportunity where Job__c = :jobNum]; opportunity.StageName = 'Cancelled'; } }else{ break; } } }catch(Exception E){ } } }
You need to add a return Statement before closing the curly braces of your global method because it has a return type.
Thanks,
like below code
Let us know if this will help you