Create Ideas from Emails

I have built an example of how you can use Salesforce Ideas and create new ideas from emails. Using Force.com Email Services to allow people to send emails and convert the emails into new Ideas.

Taking the subject line as the title of the Idea and use the body of the email as the content for the Idea.

The main class for creating the Email Services is below.

Global class IdeasSample implements Messaging.inboundEmailHandler{

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

Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

// Create the new Idea from the incoming email
        createIdea(email.subject, email.plainTextBody, env.fromAddress);
   
// Set the result to true, no need to send an email back to the user
// with an error message
result.success = true;
// Return the result for the Apex Email Service
return result;
}
Creating the Idea takes the subject, text body of the email and the from email address as arguments
public static Idea[] createIdea(String IdeaTitle, String ideaBody, String fromEmail) {

  // instance of a new Idea
  Idea[] newIdea = new Idea[0];

  // create a new Idea
  newIdea.add(new Idea(Body = ideaBody,
             Title = IdeaTitle));

   insert newIdea;
         
   sendEmail(fromEmail,newIdea);

   return newIdea;   
}   
To see the full code sample check this out

Published
June 19, 2008
Topics:

Leave your comments...

Create Ideas from Emails