• Jessica Mead
  • NEWBIE
  • 35 Points
  • Member since 2014
  • Salesforce Developer
  • TBK Bank


  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 7
    Replies
Hi - 

I am trying to create an Email Service to utilize for an Email to Lead service.  I don't want the From/To Address or Contact Name from the typical line, rather I'd like to be able to pull out fields based upon location (these are email templates getting forwarded to me from an email service).  I've successfully created the Apex Class and have repeatedly tested it with the provided email, but I'm thorouhgly stuck on creating the test class to move it to production.  Any input would be greatly appreciated!

Apex Class:

global class Email2Lead implements Messaging.InboundEmailHandler {
  global Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email,
                                                       Messaging.InboundEnvelope envelope){

    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();
     
    String[] emailBody = email.plainTextBody.split('\n');
                                                      
    system.debug('------------emailbody------'+emailBody);        

    String name = emailBody[12].substring(6);                  
    String company = emailBody[13].substring(9);                                                           
    String location = emailBody[14].substring(10);
    String phone = emailBody[15].substring(14);                                                           
    String Leademail = emailBody[16].substring(7);
    String website = emailBody[25].substring(47);
    String types = emailBody[26].substring(8);
    String currentlyadvertise = emailBody[27].substring(21);
    String target = emailBody[28].substring(9);
    String zipcode = emailBody[29].substring(11);
    Lead[] newLead = new Lead[0];
   
 try {
         if(newLead.size()==0)
         {
       newLead.add(new Lead(
       Name__c=name,Company = company,Email = Leademail,
       Location__c=Location, LastName=name, 
       Website = website,Types__c = types,Phone=phone,
       Currently_Advertise__c = currentlyadvertise,
       Target__c = target,zip_code__c = zipcode));
       insert newLead;   
    }
     }
   catch (QueryException e) {    
   }  
   result.success = true;
   return result;                                                         
  }
}




Test Class (this DOES pass, until I take it to the Validation step):

@isTest
private class TestEmail2Lead{
    static testMethod void Email2Lead(){

  // create a new email and envelope object
  Messaging.InboundEmail email = new Messaging.InboundEmail() ;
  Messaging.InboundEnvelope envelope = new Messaging.InboundEnvelope();

  // setup the data for the email
  email.subject = 'Test Job Applicant';
  email.fromname = 'FirstName LastName';
  envelope.fromAddress = 'someaddress@email.com';
  email.plainTextBody = 'email body\n2225256325\nTitle';

  // add an attachment
  Messaging.InboundEmail.BinaryAttachment attachment = new 
      Messaging.InboundEmail.BinaryAttachment();
  attachment.body = blob.valueOf('my attachment text');
  attachment.fileName = 'textfileone.txt';
  attachment.mimeTypeSubType = 'text/plain';

  email.binaryAttachments =
    new Messaging.inboundEmail.BinaryAttachment[] { attachment };

   // add an Text atatchment
  
      Messaging.InboundEmail.TextAttachment attachmenttext = new Messaging.InboundEmail.TextAttachment();
      attachmenttext.body = 'my attachment text';
      attachmenttext.fileName = 'textfiletwo3.txt';
      attachmenttext.mimeTypeSubType = 'texttwo/plain';
      email.textAttachments =   new Messaging.inboundEmail.TextAttachment[] { attachmenttext };
      
   // call the email service class and test it with the data in the testMethod
      Email2Lead testInbound=new Email2Lead ();
      testInbound.handleInboundEmail(email, envelope);
    
    // query for the lead the email service created
  Lead lead = [select id, firstName, lastName, email from lead
    where firstName = 'FirstName' and lastName = 'LastName'];
   }
}
I attempted to create a site.com site using the builder within the community, which was a simple HTML page with text and a couple videos, but wasn't able to drop this into my Community (I want to be able to click on the Navigation Menu and have the first tab take me to a static page).  After speaking with SF support, they suggested I try a Visualforce page instead.  I've created the VF page and made it available to the community profile, but I'm still not able to access it in the Community BUilder.  Can anyone assist?
Hello everyone,

I find myself at a loss with a request for a worlflow rule. The request is such:

When lookup fields A or B on an Account are populated, trigger Checkbox C on related Opportunities to be marked True.

How do I set the formula to recognize any input in fields A or B as the trigger as opposed to specific input? Anyone know?

Thank you in advance!
Service cloud web to case and email to case. Customers will sometimes send full credit card data.  This is then stored on sfdc and is a compliance issue.  Has anyone built a solution to remedy this?
I'm a newly learning SF. While doing challenge (Create a process to update child record when the parent is updated using process builder) in trailhead, following error popping up. Kindly help. 

"Challenge Not yet complete... here's what's wrong: 
An update to an account record failed to update the mailing address fields of all child contact records. Make sure that the process is correct and that it is activated."
As a part of a Trailhead Challenge I need to update an "account" filed but all I can find is "opportunity."  What am I doing wrong? User-added image