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