Inbound email services in salesforce

Lets see how we can use them and demo an example for same. We can receive a email in salesforce and use the information contained in that email i.e access that information in apex and act accordingly on that information.

Lets define a problem and work on it.
Requirement: Create a account record, record should be automatically created when a user sends an email(email will contain all the fields information)

Step 1: create a global class that can receive that email as below

global class InbEmailHandlerClass implements Messaging.InboundEmailHandler {
 global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        String emailBody = EncodingUtil.urldecode(email.plaintextbody,'utf-8');
       string[] emaildata = emailbody.split(',');
       Account cobj = new Account(); emaildata[0];
       cobj.Accountnumber = emaildata[1];
       cobj.Industry = emaildata[2];
       insert cobj;
       result.success = true;
       return result;

Step 2: You need email address to receive the email. Go to set up -> develop -> email services -> new email services.
 In new email services fill following fields
 1. name: any name you wish
 2. apex class: above class that you created
 3. Active: checked
 4.Click save.
 5. On detail email services record related list create new email address.Fill in the accept from email addresses as per your wish.
    This will be your email address to which the emails should be sent.

Step 3. Send an email from your chosen address to your salesforce email address you saved in step 2
      email format: Remember as per our class you should send field values coma separated and in proper order. That is as an example;
      Email body: testaccountname,1234,Banking
Once a email is sent, your account record would be created(If there are no other validations)

1 comment:

  1. A smallish campaign with a homemade list would not be likely to yield much of a result. To achieve anything worthwhile, a much more aggressive effort is needed. Then, the age-old value analysis applies: projected earnings = margin on total projected sales - cost of campaign.