Tuesday, September 18, 2012

EMAIL SERVICES IN SALESFORCE-EXAMPLE

I shared about the Salesforce's Email Services in my previous post..Creating Record by sending email to Salesforce - Part 1..

With this Email Service our part is to create an Apex Class to fetch the details from the email which we sent to Salesforce.

To fetch the data from incoming email we should make use of the Inbound Email messaging feature.

For Example:


global class recordfromEmail implements Messaging.InboundEmailHandler {

  global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,
    Messaging.InboundEnvelope envelope) {

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

Oppotunity Oppty = New Oppotunity();

       String[] emailBody = email.plainTextBody.Split('\n',0); 
       
       oppty.Name = emailBody[0]; 
      
       oppty.Stage = emailBody[1]; 

       insert oppty;

  return Result;
 }

}

No comments:

Post a Comment