1

This is a follow up to my previous question of Is there anyway to deactivate a trigger in Prod when the minumum code coverage is not met.

I am not an apex developer and I am the only SFDC Admin at my company. We are a smaller non-profit org and the directive is to use standard "out of the box" functionality which I can do with my declarative coding knowledge. Probelm is, Admins before me created some triggers and did not create enough test classes for them to meet the minimum code coverage of 75%. This means I cannot deploy any changes via Change Sets, I have to do it all manually which is what i have been doing. Now we have another trigger created by a previous admin that is causing errors for my users due to a change in Roles/permissions that needed to be implemented. Because I cannot de-activate this trigger (which is not even needed, no one seems to know the reason it was created) users will keep getting the errors and I cannot do any further enhancements needed. Salesforce will not help since it's custom code but they did supply me with the classes that do not have enough code coverage. It looks to me like they are already test classes though so I'm not sure if I need to create a new Test class for it or edit the existing. I'm really in a bind and I've exhausted all efforts and knowledge at this point and I'm sure the users as well as my boss will be expecting a resolution. Any insight or assistance would be greatly appreciated. There are 4 classes according to SFDC and here is the code for 1 of them:

/* * Tests */

/* * This is the basic test */

public with sharing class testSendEmailFlowPlugin {

 public static final String SUBJECT = 'Subject of Test Email';
 public static final String SUBJECT1 = 'Subject of Test Email with Only Email Address';
 public static final String BODY = 'BODY of Test Email';
 public static final String EMAIL_ADDRESS = 'blah@blah.org';
 public static final String TEXT_ATTACHMENT_NAME = 'My Text Attachment';
 public static final String TEXT_ATTACHMENT_BODY = 'My Text Attachment BODY';
 public static final String PDF_ATTACHMENT_NAME = 'My PDF Attachment.pdf';
 public static final String PDF_ATTACHMENT_BODY = 'My PDF Attachment BODY';
 public static final String INVALIDID = '000000000000000';   

static testMethod void basicTest() {

    // Create dummy lead
    Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe', Email='tuser15@salesforce.com');
    insert testLead;


    // Test Sending Email against a record
    SendEmail aSendEmailPlugin = new SendEmail();
    Map<String,Object> inputParams = new Map<String,Object>();
    Map<String,Object> outputParams = new Map<String,Object>();

    inputParams.put('recordID',testLead.ID);
    inputParams.put('subject',SUBJECT);
    inputParams.put('body',BODY);

    Process.PluginRequest request = new Process.PluginRequest(inputParams);
    Process.PluginResult result;
    result = aSendEmailPlugin.invoke(request);

    System.assertEquals(result.outputparameters.get('Status'),'SUCCESS');

    Task aTask = [select Subject from Task where WhoID = :testLead.ID];
    System.AssertEquals(aTask.Subject, 'Email: Subject of Test Email');

    Lead aLead = [select name, (SELECT Subject, ActivityDate, Description from ActivityHistories) FROM Lead where id=:testLead.ID];

// System.assert(aLead.ActivityHistories.size()==1); // System.assertEquals(aLead.ActivityHistories[0].subject, 'Email: '+SUBJECT);

}


static testMethod void basicTestwithTextAttachment() {

    // Create dummy lead
    Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe', Email='tuser15@salesforce.com');
    insert testLead;


    // Test Sending Email against a record
    SendEmail aSendEmailPlugin = new SendEmail();
    Map<String,Object> inputParams = new Map<String,Object>();
    Map<String,Object> outputParams = new Map<String,Object>();

    inputParams.put('recordID',testLead.ID);
    inputParams.put('subject',SUBJECT);
    inputParams.put('body',BODY);
    inputParams.put('textAttachmentName',TEXT_ATTACHMENT_NAME);
    inputParams.put('textAttachmentContent',TEXT_ATTACHMENT_BODY);

    Process.PluginRequest request = new Process.PluginRequest(inputParams);
    Process.PluginResult result;
    result = aSendEmailPlugin.invoke(request);

    System.assertEquals(result.outputparameters.get('Status'),'SUCCESS');
    Lead aLead = [select name, (SELECT Subject, ActivityDate, Description from ActivityHistories) FROM Lead where id=:testLead.ID];

// System.assert(aLead.ActivityHistories.size()==1); // System.assertEquals(aLead.ActivityHistories[0].subject, 'Email: '+SUBJECT);

    Attachment anAttach = [select id, name from Attachment where parentID = :testLead.ID];
    System.AssertEquals(anAttach.name, TEXT_ATTACHMENT_NAME);

}


static testMethod void basicTestwithpdfAttachment() {

    // Create dummy lead
    Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe', Email='tuser15@salesforce.com');
    insert testLead;


    // Test Sending Email against a record
    SendEmail aSendEmailPlugin = new SendEmail();
    Map<String,Object> inputParams = new Map<String,Object>();
    Map<String,Object> outputParams = new Map<String,Object>();

    inputParams.put('recordID',testLead.ID);
    inputParams.put('subject',SUBJECT);
    inputParams.put('body',BODY);
    inputParams.put('pdfAttachmentName',PDF_ATTACHMENT_NAME);
    inputParams.put('pdfAttachmentContent',PDF_ATTACHMENT_BODY);

    Process.PluginRequest request = new Process.PluginRequest(inputParams);
    Process.PluginResult result;
    result = aSendEmailPlugin.invoke(request);

    System.assertEquals(result.outputparameters.get('Status'),'SUCCESS');
    Lead aLead = [select name, (SELECT Subject, ActivityDate, Description from ActivityHistories) FROM Lead where id=:testLead.ID];

// System.assert(aLead.ActivityHistories.size()==1); // System.assertEquals(aLead.ActivityHistories[0].subject, 'Email: '+SUBJECT);

    Attachment anAttach = [select id, name from Attachment where parentID = :testLead.ID];
    System.AssertEquals(anAttach.name, PDF_ATTACHMENT_NAME);

}

/* * This test is to test the convert Lead with the Account ID specified */ static testMethod void basicTestwithCCEmail() {

    // Create dummy lead
    Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe', Email='tuser15@salesforce.com');
    insert testLead;


    // Test Sending Email against a record
    SendEmail aSendEmailPlugin = new SendEmail();
    Map<String,Object> inputParams = new Map<String,Object>();
    Map<String,Object> outputParams = new Map<String,Object>();

    inputParams.put('recordID',testLead.ID);
    inputParams.put('subject',SUBJECT);
    inputParams.put('body',BODY);
    inputParams.put('emailAddress',EMAIL_ADDRESS);

    Process.PluginRequest request = new Process.PluginRequest(inputParams);
    Process.PluginResult result;
    result = aSendEmailPlugin.invoke(request);

    System.assertEquals(result.outputparameters.get('Status'),'SUCCESS');

    Lead aLead = [select name, (SELECT Subject, ActivityDate, Description from ActivityHistories) FROM Lead where id=:testLead.ID];

// System.assert(aLead.ActivityHistories.size()==1); // System.assertEquals(aLead.ActivityHistories[0].subject, 'Email: '+SUBJECT); // System.assertEquals(aLead.ActivityHistories[0].Description.contains(EMAIL_ADDRESS), True);

}

static testMethod void basicTestwithTextAttachmentandCCEmail() {

    // Create dummy lead
    Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe', Email='tuser15@salesforce.com');
    insert testLead;

    // Test Sending Email against a record
    SendEmail aSendEmailPlugin = new SendEmail();
    Map<String,Object> inputParams = new Map<String,Object>();
    Map<String,Object> outputParams = new Map<String,Object>();

    inputParams.put('recordID',testLead.ID);
    inputParams.put('subject',SUBJECT);
    inputParams.put('body',BODY);
    inputParams.put('emailAddress',EMAIL_ADDRESS);
    inputParams.put('textAttachmentName',TEXT_ATTACHMENT_NAME);
    inputParams.put('textAttachmentContent',TEXT_ATTACHMENT_BODY);

    Process.PluginRequest request = new Process.PluginRequest(inputParams);
    Process.PluginResult result;
    result = aSendEmailPlugin.invoke(request);

    System.assertEquals(result.outputparameters.get('Status'),'SUCCESS');       

    Lead aLead = [select name, (SELECT Subject, ActivityDate, Description from ActivityHistories) FROM Lead where id=:testLead.ID];

// System.assert(aLead.ActivityHistories.size()==1); // System.assertEquals(aLead.ActivityHistories[0].subject, 'Email: '+SUBJECT); // System.assertEquals(aLead.ActivityHistories[0].Description.contains(EMAIL_ADDRESS), True); Attachment anAttach = [select id, name from Attachment where parentID = :testLead.ID]; System.AssertEquals(anAttach.name, TEXT_ATTACHMENT_NAME);

}

static testMethod void attachmentTest() {

    // Create dummy lead
    Lead testLead = new Lead(Company='Test Lead',FirstName='John',LastName='Doe', email='vrajaram@salesforce.com');
    insert testLead;

    // Create dummy conversion
    SendEmail aSendEmailPlugin = new SendEmail();
    Map<String,Object> inputParams = new Map<String,Object>();
    Map<String,Object> outputParams = new Map<String,Object>();

    inputParams.put('recordID',testLead.ID);
    inputParams.put('subject',SUBJECT);
    inputParams.put('body','testing body');
    inputParams.put('textAttachmentName','textattach');
    inputParams.put('textAttachmentContent','testing text content');
    inputParams.put('pdfAttachmentName','pdfattach');
    inputParams.put('pdfAttachmentContent','testing pdf content');



    Process.PluginRequest request = new Process.PluginRequest(inputParams);
    Process.PluginResult result;
    result = aSendEmailPlugin.invoke(request);

    System.assertEquals(result.outputparameters.get('Status'),'SUCCESS');

    Lead aLead = [select name, (SELECT Subject from ActivityHistories), (select name from Attachments) FROM Lead where id=:testLead.ID];
 //   System.assert(aLead.ActivityHistories.size()==1);
 //   System.assertEquals(aLead.ActivityHistories[0].subject, 'Email: '+SUBJECT);

    System.assert(aLead.Attachments.size()==2);
    String attach1Name = aLead.Attachments[0].name;
    String attach2Name = aLead.Attachments[1].name;

    System.assert(attach1Name == 'textattach' || attach2Name == 'textattach');
    System.assert(attach1Name == 'pdfattach.pdf' || attach2Name == 'pdfattach.pdf');




}

/* * -ve Test */ static testMethod void negativeTest() {

    // Create dummy lead


    // Test Sending Email against a record
    SendEmail aSendEmailPlugin = new SendEmail();
    Map<String,Object> inputParams = new Map<String,Object>();
    Map<String,Object> outputParams = new Map<String,Object>();

    inputParams.put('recordID',INVALIDID);
    inputParams.put('subject',SUBJECT);
    inputParams.put('body',BODY);

    Process.PluginRequest request = new Process.PluginRequest(inputParams);
    Process.PluginResult result;
    result = aSendEmailPlugin.invoke(request);

    System.assertEquals(result.outputparameters.get('Status'),'ERROR');

} 

/* * This test is to test the describe() method */ static testMethod void describeTest() {

            SendEmail aSendEmailPlugin = new SendEmail();
            Process.PluginDescribeResult result = aSendEmailPlugin.describe();

            System.AssertEquals(result.inputParameters.size(), 8);
            System.AssertEquals(result.OutputParameters.size(), 2);

    }

It says 0% code coverage but it looks like there's a lot going on there so I'm not sure what needs to be done. Any assistance would be greatly appreciated.

  • 1
    If there are 3 more of these and then the triggers they relate to, it is going to be hard to make progress on this site. (Just my opinion - I may be wrong.) Perhaps what you really need is a volunteer developer to spend some time working in your org remotely? The Salesforce Foundation provided some licenses for a non-profit I work with and in theory can provide some Salesforce employee time too; if they did that might avoid concern over exactly who a remote worker is and what their motives are. – Keith C May 23 '14 at 19:54
  • 1
    I agree with Keith. This site's format is incompatible with these types of questions, and the localization of the question makes it too specific to be answered here. However, I'd love to help you along if all else fails, so do feel free to contact me at the address on my profile. – sfdcfox May 23 '14 at 20:27
  • Thank you both for your input. There is a site that I found (sfdc99) that walks through creating test classes which I looks like it might be helpful, although not knowing which Triggers these were created for and why may be a hurdle. I see a Pro Bono area on the Foundation website so that might be a way to get assistance from someone knowledgable as well so thanks Keith. And thanks for the offer SFDCfox, if I don't get anyway or come to a hurdle I may run something by you. Thanks again guys I love how helpful everyone has been on this site. – user7417 May 23 '14 at 20:53
  • @user7417 Occurred to me that a volunteer developer working with you remotely using e.g. GoToMeeting would be pretty safe. If I was you and couldn't sort it out myself quite soon I would be taking sfdcfox up on his offer... – Keith C May 24 '14 at 9:40

Your Answer

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

Browse other questions tagged or ask your own question.