ERROR: Unable to run tests synchronously: [This class name's value is invalid: Opportunity_EmailServiceTest. Provide the name of an Apex class that has test methods.].

private class Opportunity_EmailServiceTest{

//@isTest static void test_matching_product() {
    ////send fake email
    //Messaging.InboundEmail email = new Messaging.InboundEmail();
    //email.fromAddress = userInfo.getUserEmail();
    //email.subject = 'TestCode123';
    ////create an attachment
    //Messaging.InboundEmail.BinaryAttachment att = new Messaging.InboundEmail.BinaryAttachment();
    //att.fileName = 'TestAttachment';
    //att.Body = Blob.valueOf('Test123');
    //email.binaryAttachments = new List<Messaging.InboundEmail.BinaryAttachment>{att};
    //Opportunity_EmailService serv = new Opportunity_EmailService();
    //Messaging.InboundEmailResult result = serv.handleInboundEmail(email, null);

@isTest static void testCreateOppSingle(){
    //send fake email
    Messaging.InboundEmail email = new Messaging.InboundEmail();
    email.fromAddress = userInfo.getUserEmail();
    email.subject = 'TestCode123';
    //create an attachment
    Messaging.InboundEmail.BinaryAttachment att = new Messaging.InboundEmail.BinaryAttachment();
    att.fileName = 'TestAttachment';
    att.Body = Blob.valueOf(
    email.binaryAttachments = new List<Messaging.InboundEmail.BinaryAttachment>{att};
    Opportunity_EmailService serv = new Opportunity_EmailService();
    Messaging.InboundEmailResult result = serv.handleInboundEmail(email, null);
    Opportunity createdOpp = [Select Id, Name, Amount, StageName, CloseDate from Opportunity limit 1];
    System.assertEquals(createdOpp.Name, 'Test Opportunity Name');
    System.assertEquals(createdOpp.Amount, 100000);
    System.assertEquals(createdOpp.StageName, 'Closed Won');
    System.assertEquals(createdOpp.CloseDate, '2018-01-01:00:00');

Class being tested.

global class Opportunity_EmailService implements Messaging.InboundEmailHandler {
public Messaging.InboundEmailResult handleInboundEmail(Messaging.inboundEmail email, Messaging.InboundEnvelope env) {
    Messaging.InboundEmailResult result = new Messaging.InboundEmailResult();

        List<Opportunity> oppsToUpsert = new List<Opportunity>();
        for(Messaging.InboundEmail.BinaryAttachment att : email.binaryAttachments){

            String attBody = att.Body.toString();
            for(String row : attBody.split('\r\n')) {
                String oppData = row.split(',');
                Opportunity o = new Opportunity();

                o.Name = oppData[0];

                String dateConcat = oppData[1] + ':' + 00 + ':' + 00;
                o.CloseDate = dateConcat;

                o.Amount = Integer.valueOf(oppData[3]);

                o.StageName = oppData[2];

    //catch(Exception e){
    //  system.debug(e);
    //  system.debug(e.getStackTraceString());
    return result;

Figured it out. A number of errors here. My code in the class isn't in a method. Also typecasting error on oppData. oppstoupsert needs to be in that last for loop etc etc. Disregard.

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.