9

I have created an email service based on the Salesforce documentation found at the following address:

https://help.salesforce.com/apex/HTViewHelpDoc?id=code_email_services_editing.htm

The only issue is that my class (which clearly impliments the InboundEmailHandler) is not being recognised as a compatible email service class.

My class:

global class processEnquiryEmail implements Messaging.InboundEmailHandler {
 global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { 
   Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

   Inbound_Email__c ie = new Inbound_Email__c(); 
   ie.From__c = email.fromname; 
   ie.Body__c = email.plainTextBody; 
   ie.Subject__c = email.subject; 
   ie.Email__c = envelope.fromAddress;

   try{insert ie;}
   catch(Exception e){
      system.debug('There was an error processing the email. ' + ie); }   
   return result; 
  }
}

and I am getting the following error when i try to activate my email service:

The Apex Class selected is not valid. An Apex Class that implements the Messaging.InboundEmailHandler interface must be selected.

Does anyone know why I can not use the above class in my email service? What is making it incompatible?

11

After speaking to Salesforce support I have resolved the issue. Rather than delete the post i will answer it incase anyone has similar issues...

The support consultant literally took a copy of my class, deleted it from the system and reinstated it again. After doing this the class became compatible with the Email Service despite no code changing.

I recommend following the above steps before racking your brains over it as I did. It is obviously just a Salesforce bug...

| improve this answer | |
  • i have a vague genetic memory that if the class is not marked as active, it can't be selected. I seem to recall having to write a testmethod and executing it (probably could use anonymous apex too) to get the class to be acceptable – cropredy Jan 28 '15 at 1:56
  • 2
    I actually already had a test method, run with 90% coverage (stupid try-catches) and the apex class was definitely active. This has happened to me in the past but with scheduled apex classes, never with email services.. It is obviously a bug across the board that developers need to be aware of – David Dawson Jan 28 '15 at 2:14
  • my other vague genetic memory was that I had to create the class using the UI not Eclipse to get it to be accepted ...but this of course was not consistent – cropredy Jan 28 '15 at 2:22
  • 2
    I just ran into this. The class is invalid (needs recompilation). If you go to the Apex Class listing page and filter on Is Valid = false, you'll see it listed. 'Compile All' of the classes from that listing page and then the classes should go away in the Is Valid = true filtered list view. Then you can use the class in the Email Service setup. – Peter Knolle Sep 15 '16 at 18:51
2

I faced the same issue with Email Services (with a bonus of Sandbox vs Production problem).

I created a class in the sandbox that implemented the Messaging.InboundEmailHandler interface which worked fine in the sandbox but I got the same error in production, after reading the solution support gave to David I tried something that shouldn't work but it did.

I fixed the error (or find a workaround for the bug) by compiling the class in production from the IDE (I'm using MavensMate) and then I was able to create the Email Service without any problem.

Note: Just in case you can't wait for support to get back to you.

| improve this answer | |
1

This error indicates that the packaged Apex Class has not yet been compiled. Typically, Apex Classes are compiled when saved. However, Apex Classes associated with Managed Packages cannot be saved so they rely on the runtime engine to compile them, either when they are first used or at some point automatically after they are installed.

If you encounter this error, please follow the steps below to manually compile that Apex Class:

  1. Navigate to Setup > Develop > Apex Classes.
  2. On the Top Left, click the link labeled “Compile all classes”.
  3. Once Compilation is complete, reattempt setting up the Email Service

Thanks I hope this will helps you.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.