0

this code is working and view all the data on my vf detail page but i want to extract signature like this is my mail

hello salesforce

--
Thanks and regards
Vipin Indora
mob no- 1234567890

i want signature which is represent in bold letter

global class ProcessContactApplicantEmail 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.fromname.substring(email.fromname.indexOf(' '));
        contact.Email = envelope.fromAddress;
        contact.from__c = email.subject;
        contact.Signature__c = email.plainTextBody;
        insert contact;

        System.debug('====> Created contact==> '+contact.Id);

        if (email.binaryAttachments != null && email.binaryAttachments.size() > 0) {
          for (integer i = 0 ; i < email.binaryAttachments.size() ; i++) {
            Attachment attachment = new Attachment();
            // attach to the newly created contact record
            attachment.ParentId = contact.Id;
            attachment.Name = email.binaryAttachments[i].filename;
            attachment.Body = email.binaryAttachments[i].body;
            insert attachment;
            system.debug('---> '+attachment.name+' @@@@ '+attachment.body);
          }
    }
       return result;
    }



}
  • why don't you use split tag to split it and get the signature? – Tushar Sharma Feb 4 '16 at 9:34
  • show the example of split tag – Vipin Indora Feb 4 '16 at 10:14
0

you can try substringAfterLast in your case. It will solve your problem.

string bodystr = email.plainTextBody;
string signature = bodystr.substringAfterLast('--');
contact.Signature__c = signature;
  • not sure about the requirment – Tushar Sharma Feb 4 '16 at 12:58
  • try regex to find – Tushar Sharma Feb 5 '16 at 6:59
  • var numberPattern = /\d+/g; 'something102asdfkj1948948'.match( numberPattern ) this will return an array of all number. – Tushar Sharma Feb 5 '16 at 7:12
  • sample string. replace it with your. – Tushar Sharma Feb 5 '16 at 7:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.