+ Start a Discussion

SOQL Failure for no discernable reason :(

Hi folks,


I'm using an inbound email handler so that users in my organisation who aren't particularly familiar with Chatter can post to Chatter any useful information they might have. However, the code below is doing some weird stuff (described below the code).


global class EmailtoChatter implements Messaging.InboundEmailHandler {
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        List<User> ChatterUser = [select id, Name, Email from User where Email =: email.fromAddress and IsActive = true limit 1];
        String s = '%'+email.Subject+'%';
        List<Account> AccRef = [select id, Name from Account where (Name like :s or Short_Name__c like :s) and ParentID = null limit 1];
            FeedItem a = new FeedItem();
            a.CreatedByID = ChatterUser[0].id;
            a.Body = email.PlainTextBody;
            a.ParentID = AccRef[0].id;
            insert a;
        return result;


1) It works fine if I, system administrator, email to the inbound service I've set up.

2) If I try to email a post to chatter via the inbound service as a Chatter Free User in the Developer Environment, nothing happens (no debug log, nothing).

3) If I specify the ID of the Chatter Free User, rather than using the list, the Chatter Free User posts a comment, containing the contents of the email to the Account, even though he can't see the Account by logging into Salesforce, exactly as I had intended.

4) If I specify the ProfileID of Chatter Free User in the SOQL for users, I get a list of no size returned, even though I clearly have a Chatter Free User.




So that works in my dev environment when I send from both user email addresses (admin and chatter free) so I am wondering if the issue is with the email service? Sounds like th eservice never gets the email from the chatter free user.


When you set email services, it by default restricts the addresses it will receive from to the user creating it (usually your current sys admin email address) - so check both the service and the email address you are using  for the service that it can receive from any address...