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
AzarudeenAzarudeen 

send a mail to salesforce.com, create a lead

 

send a mail to salesforce.com, create a lead. but company address is not working. yahoo,gmail are working below code
Global class unsubscribe implements Messaging.inboundEmailHandler{
Global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,Messaging.InboundEnvelope env )
 {
// Create an inboundEmailResult object for returning
//the result of the Apex Email Service
Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();
 
String strEmailId = email.fromAddress.toLowerCase();
String strSubject = email.subject.toLowerCase();
String emailBody1 = email.plainTextBody.toLowerCase();
String[] strTemp=strEmailId.split('@',0);   // first split with @, you'll get [jaya, global.com] in array
String temp = strTemp[1];
String[] comp=temp.split('\\.',0);     // again split 2nd element of array with dot(.)
String compa = comp[0].toLowerCase();            // It shows the compny name 'global' in debug log
 
 integer iCount;
 iCount = [select count() from Lead where Email=:email.fromAddress];
 
   if (iCount==0)
   {   
   Lead l = new lead(
           FirstName='Mailing Lead1',    //firstname
           LastName='Mailing Lead1',     //Lastname           
           Email=strEmailId,             //email      
           Company=compa,                //company
           Title=strSubject,              // title
           Description=emailBody1,        //description
           Status='Open-Not Contacted',
           HasOptedOutOfEmail=true,
           OwnerId='00590000000Oy12AAC');
          
   insert l;
   }
 
result.success = true;
return result;
    }  
    }

Global class unsubscribe implements Messaging.inboundEmailHandler{Global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email,Messaging.InboundEnvelope env ) {// Create an inboundEmailResult object for returning//the result of the Apex Email ServiceMessaging.InboundEmailResult result = new Messaging.InboundEmailResult(); String strEmailId = email.fromAddress.toLowerCase();String strSubject = email.subject.toLowerCase();String emailBody1 = email.plainTextBody.toLowerCase();


String[] strTemp=strEmailId.split('@',0);   // first split with @, you'll get [jaya, global.com] in arrayString temp = strTemp[1];String[] comp=temp.split('\\.',0);     // again split 2nd element of array with dot(.)String compa = comp[0].toLowerCase();            // It shows the compny name 'global' in debug log 
 integer iCount; iCount = [select count() from Lead where Email=:email.fromAddress];    if (iCount==0)   {      Lead l = new lead(           FirstName='Mailing Lead1',    //firstname           LastName='Mailing Lead1',     //Lastname                      Email=strEmailId,             //email                 Company=compa,                //company           Title=strSubject,              // title           Description=emailBody1,        //description           Status='Open-Not Contacted',           HasOptedOutOfEmail=true,           OwnerId='00590000000Oy12AAC');             insert l;   } result.success = true;return result;    }      }