Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8210049
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T09:56:28+00:00 2026-06-07T09:56:28+00:00

I have written a working class in Apex. It is an Email service extender,

  • 0

I have written a working class in Apex. It is an Email service extender, that processes incoming emails.
It is working perfect on my sandbox enviroment.

I have created a test class, so I can also deploy it to my production, but when validating the code, I get the only 72% of my code is tested.

This is my main class

global class inboundEmail implements Messaging.InboundEmailHandler {

global Messaging.InboundEmailResult handleInboundEmail(Messaging.InboundEmail email, Messaging.InboundEnvelope envelope) {
    Messaging.InboundEmailResult result = new Messaging.InboundEmailresult();

Lead lead;

String [] mFromUserParams;
String [] sourceText;
String mCaseObject; 

try{
    sourceText = email.toAddresses[0].split('@');
    String [] mParams = sourceText[0].split('\\.');
**// FROM THIS LINE TO THE END - NOT COVERED**
    mFromUserParams = email.fromAddress.split('@');
    mCaseObject = mParams[0];
    if (mCaseObject == 'lead'){
        lead = new Lead();
        lead.LastName = mFromUserParams[0];
        lead.Company = email.fromAddress;
        lead.OwnerId = mParams[1];
        lead.LeadSource = mParams[2];
        lead.Email = email.fromAddress;
        lead.RequirementsDescription__c = email.subject + email.plainTextBody;

        insert lead;
        result.success = true;
    }  else if (mCaseObject == 'case'){
        result.success = true;
    }  else {
        result.success = false;
    }
}catch(Exception e){
    result.success = false;
    result.message = 'Oops, I failed.';
}
return result;
}
}

This is my test class

@isTest
private class inboundEmailTest {
public static testMethod void inboundEmail(){     
    // Create a new email, envelope object and Header
    Messaging.InboundEmail email = new Messaging.InboundEmail();
    Messaging.InboundEnvelope envelope = new Messaging.InboundEnvelope();
envelope.toAddress = 'lead.owner.new@cpeneac.cl.apex.sandbox.salesforce.com';
    envelope.fromAddress = 'user@acme.com';
    email.subject = 'Please contact me';
    email.fromName = 'Test From Name';
    email.plainTextBody = 'Hello, this a test email body. for testing  Bye';
    // setup controller object
    inboundEmail catcher = new inboundEmail();
    Messaging.InboundEmailResult result = catcher.handleInboundEmail(email, envelope);
}
}

According to the error message, ALL lines in the Try/Catch block from the 3rd line are not covered. (marked in the code).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T09:56:29+00:00Added an answer on June 7, 2026 at 9:56 am

    The email.fromAddress is not a list by default, so just setting that to a string and not a list solved this.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am working on struts2. In my action class I have written some accessors
I'm working on an app (Written in C#) that have a setting to run
I have written a class in python that implements __str__(self) but when I use
I have written a windows service that uses the openpop mail client and retreives
this is a working example of a plugin that I have written for CRM
I'm currently working on a trivia game. I have written a Team class, a
I have written an ActiveX control in C# and have made it working using
I have written a query like this. It is working and giving me the
Good Morning, I'm working on an ASP.NET 3.5 webforms application and have written the
I'm working on a video codec for OMAP3430. I already have code written in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.