Thursday 15 January 2015

Email services in salesforce

Email services are automated processes that use Apex classes to process the contents, headers, and attachments of inbound email. For example, you can create an email service that automatically creates contact records based on contact information in messages.

Basic Synatx:



Before creating email services, create Apex classes that implement the Messaging.InboundEmailHandler interface.

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

Examples:

example 1:

global class createcontact implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { Messaging.InboundEmailResult result = new Messaging.InboundEmailresult(); Contact contact = new Contact(); contact.FirstName = email.fromname.substring(0,email.fromname.indexOf(' ')); contact.LastName = email.subject; contact.Email = envelope.fromAddress; contact.LeadSource = 'other'; insert contact; System.debug('====> Created contact '+contact.Id); return result; } }
----------------------------------------------------------------
example 2:
global class createevent1 implements Messaging.InboundEmailHandler { global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) { Messaging.InboundEmailResult result = new Messaging.InboundEmailresult(); event e = new event(); e.Ownerid='00590000002dteE'; e.Subject = 'email'; e.StartDateTime = system.Now(); e.EndDateTime = system.Now()+1; insert e; System.debug('====> Created event '+e.Id); return result; } }

No comments:

Post a Comment

Complete Salesforce CPQ training Free videos

Salesforcestart:: We are excited to announce that our YouTube channel, Salesforcestart, is your one-stop-shop for all things Salesforce CPQ!...