MK Partners Archive for March, 2008

Jotting directly into Salesforce

Last week, I started using Jott.com.  If you’re not familiar with their service, it is essentially a personal dictation secretary.  You call Jott.com, pick a contact from your address book and then start talking.  Jott.com transcribes your message and emails the person the resulting text as well as a link to listen to your recording.

We normally try to not excessively promote services and products on this blog, but we liked Jott.com so much that we decided to build Jott-2-Salesforce.  We leveraged Apex Email Services to automatically create a task in Salesforce every time we leave ourselves a message on Jott.  Here’s a generic version of the Class, have fun!

Global class Jott_Note_To_Self implements Messaging.inboundEmailHandler{

Global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope env ) {

    // Create an inboundEmailResult object for returning the result of the Apex Email Service
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
 
    // If unsubscribe is found in the subject line enter the if statement
        try {
             // Create a new Task
            Task t = new Task();
            t.Subject = email.subject;
            t.Description = email.plainTextBody;
            t.Status = ‘Not Started’;
            t.Priority = ‘Normal’;
            insert t;
         } catch (exception e) {
        }    

    // Return true and exit
    // True will confirm it is complete and no bounced email
    result.success = true;
    return result;
}   

static testMethod void testUnsubscribe() {

    // Create a new email and envelope object
   Messaging.InboundEmail email = new Messaging.InboundEmail() ;
   Messaging.InboundEnvelope env = new Messaging.InboundEnvelope();

   // test with subject that matches the unsubscribe statement
   email.subject = ‘test jott’;
   env.fromAddress = ‘support@salesforce.com’;
  
   // call the class and test it with the data in the testMethod
   Jott_Note_To_Self jott = new Jott_Note_To_Self();
   jott.handleInboundEmail(email, env );
                       
}

}