function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
NK@BITNK@BIT 

Parse the Email body and create a record in object

I have an object "Leave"

I want that if i send a mail using "Email Service Address" and in Email body i sends StartDate and EndDate Value,

Than StartDate and EndDate Values insert into the Start_Date__c and End_Date__c field of "Leave" Object.

So please tell me how to do this.
DevADSDevADS
1) Create a following class :

global class myHandler implements Messaging.InboundEmailHandler {
    global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
        Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
        List<String> emailPlainTextBody = email.plainTextBody.split('\n');
        Leave__c leaveObj = new Leave__c();
        leaveObj.StartDate__c = emailPlainTextBody[0];
        leaveObj.EndDate__c = emailPlainTextBody[1];
        insert leaveObj;
        return result;
    }

}

2) Now create a Email Service.

That's about it ! Happy Coding!!!
asish1989asish1989
Hi 
If you try this code then some error will be fired because string value can never be assigned to date variable. 

leaveObj.StartDate__c = emailPlainTextBody[0];
leaveObj.EndDate__c = emailPlainTextBody[1];

Instaed of that two line you have to write 

leaveObj.StartDate__c = Date.ValueOf(emailPlainTextBody[0]);
leaveObj.EndDate__c = Date.ValueOf(emailPlainTextBody[1]);


For more information about emal service go through this tw link 

http://wiki.developerforce.com/page/An_Introduction_To_Email_Services_on_Force.com

http://salesforceworld4u.blogspot.in/2013/05/emailservice-in-salesforce.html

DevADSDevADS
Yeah, Please follow the Ashish!