Salesforce Test class showing 50% test coverage always












0















I have written an Apex Batch schedulable class that runs a method from another class everyday at a certain time. What this batch class does is see all the accounts that have a field "Email Sent__c" as true and if it is true, it will pass those clients to the execute function so that it runs a method from a different class. this method basically generates an email and sends it. Once the email is sent, it updates the field Email_Sent__c to false. Everything works great and now in order to deploy it, I am writing some test classes. The problem is that the test class I have written for the Batch Apex only shows 50% coverage. Can someone please let me know why this is only 50% and what I can do to fix it? Also, I dont think the system.assert calls are checking the email_sent values after the update, they are only taking the values from the test setup method



Here is the Batch Apex class I wrote:
global class ConfirmationCardBatchApex implements Database.Batchable, Database.Stateful {
global Database.QueryLocator start(Database.BatchableContext BC) {
Datetime clientReleasedDate = Datetime.now().addHours(-24);



    return Database.getQueryLocator(
'SELECT Id, Client_Released__c, Client_Number__c, Release_Date__c, ' +
'Email_Sent__c FROM Account ' +
'WHERE Email_Sent__c = true AND Client_Released__c = true AND Release_Date__c<=:clientReleasedDate'
);


}
global void execute( Database.BatchableContext BC, List<Account> scope){
List<String> acctIdList = new List<String>();
for(Account account : scope){
acctIdList.add(account.Id);

}
LM_ChangeAccountRT.resendEmails(acctIdList);
} //this block of code, the execute method keeps on showing that its uncovered by my testclass!!!

global void finish(Database.BatchableContext bc){
System.debug( 'finish: called' );
}


}



The test class I wrote is the following (I am sure it has alot of mistakes. what can i do to get 100% coverage?)



@isTest
public class TestConfirmationCardBatchApex {
static Account client;
static Account client1;
static Account client2;
static Account parentC;
static Contact con;

@testSetup
Contact cont1 = new Contact(LastName='ContTest1', Email='test1contact@libertymutual.com', CommunicationType__c ='Holiday card', recordTypeId = Schema.SObjectType.contact.getRecordTypeInfosByName().get('Business Development Manager').getRecordTypeId(),FirstName= 'Contact');
insert cont1;

id tempuser = [Select id from User where LastName='Testing' limit 1].id;
system.debug('11111'+tempuser);
parentC = TestDataUtils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
parentC.Dealership_Partner__c = 'BMW';
parentC.Dealership_State__c='WA';
parentC.Name = 'Parent Name';
parentC.Client_Number__c = '12302.0';
parentC.Business_Development_Manager__c=cont1.id;
insert parentC;

client1 = TestDataUTils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
client1.Name = 'Test Client 2';
client1.Business_Development_Manager__c=cont1.id;
client1.Branch_Manager__c = tempuser;
client1.Dealership_Partner__c = 'BMW';
client1.Dealership_State__c= 'TX';
client1.ParentID = parentC.Id;
client1.Client_Number__c = '12322.0';
client1.Email_Sent__c = true;
client1.Client_Released__c = true;
accountdata.add(client1);

client2 = TestDataUTils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
client2.Name = 'Test Client 3';
client2.Business_Development_Manager__c=cont1.id;
client2.Branch_Manager__c = tempuser;
client2.Dealership_Partner__c = 'BMW';
client2.Dealership_State__c= 'CA';
client2.ParentID = parentC.Id;
client2.Client_Number__c = '12332.0';
client2.Email_Sent__c = true;
client2.Client_Released__c = true;
accountdata.add(client2);
insert accountdata;
static testmethod void test() {
Test.startTest();
ConfirmationCardBatchApex confirm = new ConfirmationCardBatchApex();
Id batchId = Database.executeBatch(confirm);
Account emailTest = [SELECT Id, Name, Client_Released__c, Client_Number__c, Release_Date__c, Email_Sent__c FROM Account WHERE Name IN ('ContTest1', 'Test Client 1', 'Test Client 2') AND Email_Sent__c = true];
Test.stopTest();
System.assertEquals(true, emailTest.Email_Sent__c, 'Expected value should be true'); // After method is run, the email_sent__c should be false but it only shows success when I assert it to true.
}

}


In case you are wondering what this resendemails method is(in the LM_CHANGEACCOUNTRT Class), here is a snippet of it:



@AuraEnabled
public static String resendEmails(List<String> accountIdList) {
String response = null;
try {
//Only send emails if user is either an ARMS Administor or System Administrator
if (System.label.ARMS_Administrator_Profile_Id == userinfo.getProfileId() ||
sysAdmin.Id == userinfo.getProfileId()) {
List<Account> accList = [SELECT Id,FCA_Dealership__c,Branch_Manager__c,Business_Development_Manager__c,Client_Released__c,Existing_Participant__c,
Dealership_Partner__c,Dealership_State__c,RecordTypeId,owner.email,owner.Supervisor_Email__c,Client_Number__c,Closing_Manager__r.name,
Name,Completed_Date__c,Effective_Date__c,Closing_Manager__c,Is_the_client_receiving_compensation__c,Is_a_broker_receiving_compensation__c,Broker__r.name,
,Broker__r.State__c, Email_Sent__c,
FROM Account
WHERE Id IN:accountIdList];

for(Account acc: accList){
if (acc.Client_Number__c != null && acc.Client_Released__c && acc.Email_Sent__c == true) {
sendpdfgenerationEmails(acc);
acc.Email_Sent__c = false;

response = 'Email Sent';
}else {
response= 'Access Denied';
}
}

update accList;
}
}catch(Exception e) {
System.debug(e.getMessage());
response = 'Error sending emails';
}
return response;
}//what this method does is call the sendpdfgeneration method which is the method that generates and sends a custom email. After calling the method, the email_sent__c field is updated to false


Any help in fixing my test method would be greatly appreciated. Thank you










share|improve this question



























    0















    I have written an Apex Batch schedulable class that runs a method from another class everyday at a certain time. What this batch class does is see all the accounts that have a field "Email Sent__c" as true and if it is true, it will pass those clients to the execute function so that it runs a method from a different class. this method basically generates an email and sends it. Once the email is sent, it updates the field Email_Sent__c to false. Everything works great and now in order to deploy it, I am writing some test classes. The problem is that the test class I have written for the Batch Apex only shows 50% coverage. Can someone please let me know why this is only 50% and what I can do to fix it? Also, I dont think the system.assert calls are checking the email_sent values after the update, they are only taking the values from the test setup method



    Here is the Batch Apex class I wrote:
    global class ConfirmationCardBatchApex implements Database.Batchable, Database.Stateful {
    global Database.QueryLocator start(Database.BatchableContext BC) {
    Datetime clientReleasedDate = Datetime.now().addHours(-24);



        return Database.getQueryLocator(
    'SELECT Id, Client_Released__c, Client_Number__c, Release_Date__c, ' +
    'Email_Sent__c FROM Account ' +
    'WHERE Email_Sent__c = true AND Client_Released__c = true AND Release_Date__c<=:clientReleasedDate'
    );


    }
    global void execute( Database.BatchableContext BC, List<Account> scope){
    List<String> acctIdList = new List<String>();
    for(Account account : scope){
    acctIdList.add(account.Id);

    }
    LM_ChangeAccountRT.resendEmails(acctIdList);
    } //this block of code, the execute method keeps on showing that its uncovered by my testclass!!!

    global void finish(Database.BatchableContext bc){
    System.debug( 'finish: called' );
    }


    }



    The test class I wrote is the following (I am sure it has alot of mistakes. what can i do to get 100% coverage?)



    @isTest
    public class TestConfirmationCardBatchApex {
    static Account client;
    static Account client1;
    static Account client2;
    static Account parentC;
    static Contact con;

    @testSetup
    Contact cont1 = new Contact(LastName='ContTest1', Email='test1contact@libertymutual.com', CommunicationType__c ='Holiday card', recordTypeId = Schema.SObjectType.contact.getRecordTypeInfosByName().get('Business Development Manager').getRecordTypeId(),FirstName= 'Contact');
    insert cont1;

    id tempuser = [Select id from User where LastName='Testing' limit 1].id;
    system.debug('11111'+tempuser);
    parentC = TestDataUtils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
    parentC.Dealership_Partner__c = 'BMW';
    parentC.Dealership_State__c='WA';
    parentC.Name = 'Parent Name';
    parentC.Client_Number__c = '12302.0';
    parentC.Business_Development_Manager__c=cont1.id;
    insert parentC;

    client1 = TestDataUTils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
    client1.Name = 'Test Client 2';
    client1.Business_Development_Manager__c=cont1.id;
    client1.Branch_Manager__c = tempuser;
    client1.Dealership_Partner__c = 'BMW';
    client1.Dealership_State__c= 'TX';
    client1.ParentID = parentC.Id;
    client1.Client_Number__c = '12322.0';
    client1.Email_Sent__c = true;
    client1.Client_Released__c = true;
    accountdata.add(client1);

    client2 = TestDataUTils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
    client2.Name = 'Test Client 3';
    client2.Business_Development_Manager__c=cont1.id;
    client2.Branch_Manager__c = tempuser;
    client2.Dealership_Partner__c = 'BMW';
    client2.Dealership_State__c= 'CA';
    client2.ParentID = parentC.Id;
    client2.Client_Number__c = '12332.0';
    client2.Email_Sent__c = true;
    client2.Client_Released__c = true;
    accountdata.add(client2);
    insert accountdata;
    static testmethod void test() {
    Test.startTest();
    ConfirmationCardBatchApex confirm = new ConfirmationCardBatchApex();
    Id batchId = Database.executeBatch(confirm);
    Account emailTest = [SELECT Id, Name, Client_Released__c, Client_Number__c, Release_Date__c, Email_Sent__c FROM Account WHERE Name IN ('ContTest1', 'Test Client 1', 'Test Client 2') AND Email_Sent__c = true];
    Test.stopTest();
    System.assertEquals(true, emailTest.Email_Sent__c, 'Expected value should be true'); // After method is run, the email_sent__c should be false but it only shows success when I assert it to true.
    }

    }


    In case you are wondering what this resendemails method is(in the LM_CHANGEACCOUNTRT Class), here is a snippet of it:



    @AuraEnabled
    public static String resendEmails(List<String> accountIdList) {
    String response = null;
    try {
    //Only send emails if user is either an ARMS Administor or System Administrator
    if (System.label.ARMS_Administrator_Profile_Id == userinfo.getProfileId() ||
    sysAdmin.Id == userinfo.getProfileId()) {
    List<Account> accList = [SELECT Id,FCA_Dealership__c,Branch_Manager__c,Business_Development_Manager__c,Client_Released__c,Existing_Participant__c,
    Dealership_Partner__c,Dealership_State__c,RecordTypeId,owner.email,owner.Supervisor_Email__c,Client_Number__c,Closing_Manager__r.name,
    Name,Completed_Date__c,Effective_Date__c,Closing_Manager__c,Is_the_client_receiving_compensation__c,Is_a_broker_receiving_compensation__c,Broker__r.name,
    ,Broker__r.State__c, Email_Sent__c,
    FROM Account
    WHERE Id IN:accountIdList];

    for(Account acc: accList){
    if (acc.Client_Number__c != null && acc.Client_Released__c && acc.Email_Sent__c == true) {
    sendpdfgenerationEmails(acc);
    acc.Email_Sent__c = false;

    response = 'Email Sent';
    }else {
    response= 'Access Denied';
    }
    }

    update accList;
    }
    }catch(Exception e) {
    System.debug(e.getMessage());
    response = 'Error sending emails';
    }
    return response;
    }//what this method does is call the sendpdfgeneration method which is the method that generates and sends a custom email. After calling the method, the email_sent__c field is updated to false


    Any help in fixing my test method would be greatly appreciated. Thank you










    share|improve this question

























      0












      0








      0








      I have written an Apex Batch schedulable class that runs a method from another class everyday at a certain time. What this batch class does is see all the accounts that have a field "Email Sent__c" as true and if it is true, it will pass those clients to the execute function so that it runs a method from a different class. this method basically generates an email and sends it. Once the email is sent, it updates the field Email_Sent__c to false. Everything works great and now in order to deploy it, I am writing some test classes. The problem is that the test class I have written for the Batch Apex only shows 50% coverage. Can someone please let me know why this is only 50% and what I can do to fix it? Also, I dont think the system.assert calls are checking the email_sent values after the update, they are only taking the values from the test setup method



      Here is the Batch Apex class I wrote:
      global class ConfirmationCardBatchApex implements Database.Batchable, Database.Stateful {
      global Database.QueryLocator start(Database.BatchableContext BC) {
      Datetime clientReleasedDate = Datetime.now().addHours(-24);



          return Database.getQueryLocator(
      'SELECT Id, Client_Released__c, Client_Number__c, Release_Date__c, ' +
      'Email_Sent__c FROM Account ' +
      'WHERE Email_Sent__c = true AND Client_Released__c = true AND Release_Date__c<=:clientReleasedDate'
      );


      }
      global void execute( Database.BatchableContext BC, List<Account> scope){
      List<String> acctIdList = new List<String>();
      for(Account account : scope){
      acctIdList.add(account.Id);

      }
      LM_ChangeAccountRT.resendEmails(acctIdList);
      } //this block of code, the execute method keeps on showing that its uncovered by my testclass!!!

      global void finish(Database.BatchableContext bc){
      System.debug( 'finish: called' );
      }


      }



      The test class I wrote is the following (I am sure it has alot of mistakes. what can i do to get 100% coverage?)



      @isTest
      public class TestConfirmationCardBatchApex {
      static Account client;
      static Account client1;
      static Account client2;
      static Account parentC;
      static Contact con;

      @testSetup
      Contact cont1 = new Contact(LastName='ContTest1', Email='test1contact@libertymutual.com', CommunicationType__c ='Holiday card', recordTypeId = Schema.SObjectType.contact.getRecordTypeInfosByName().get('Business Development Manager').getRecordTypeId(),FirstName= 'Contact');
      insert cont1;

      id tempuser = [Select id from User where LastName='Testing' limit 1].id;
      system.debug('11111'+tempuser);
      parentC = TestDataUtils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
      parentC.Dealership_Partner__c = 'BMW';
      parentC.Dealership_State__c='WA';
      parentC.Name = 'Parent Name';
      parentC.Client_Number__c = '12302.0';
      parentC.Business_Development_Manager__c=cont1.id;
      insert parentC;

      client1 = TestDataUTils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
      client1.Name = 'Test Client 2';
      client1.Business_Development_Manager__c=cont1.id;
      client1.Branch_Manager__c = tempuser;
      client1.Dealership_Partner__c = 'BMW';
      client1.Dealership_State__c= 'TX';
      client1.ParentID = parentC.Id;
      client1.Client_Number__c = '12322.0';
      client1.Email_Sent__c = true;
      client1.Client_Released__c = true;
      accountdata.add(client1);

      client2 = TestDataUTils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
      client2.Name = 'Test Client 3';
      client2.Business_Development_Manager__c=cont1.id;
      client2.Branch_Manager__c = tempuser;
      client2.Dealership_Partner__c = 'BMW';
      client2.Dealership_State__c= 'CA';
      client2.ParentID = parentC.Id;
      client2.Client_Number__c = '12332.0';
      client2.Email_Sent__c = true;
      client2.Client_Released__c = true;
      accountdata.add(client2);
      insert accountdata;
      static testmethod void test() {
      Test.startTest();
      ConfirmationCardBatchApex confirm = new ConfirmationCardBatchApex();
      Id batchId = Database.executeBatch(confirm);
      Account emailTest = [SELECT Id, Name, Client_Released__c, Client_Number__c, Release_Date__c, Email_Sent__c FROM Account WHERE Name IN ('ContTest1', 'Test Client 1', 'Test Client 2') AND Email_Sent__c = true];
      Test.stopTest();
      System.assertEquals(true, emailTest.Email_Sent__c, 'Expected value should be true'); // After method is run, the email_sent__c should be false but it only shows success when I assert it to true.
      }

      }


      In case you are wondering what this resendemails method is(in the LM_CHANGEACCOUNTRT Class), here is a snippet of it:



      @AuraEnabled
      public static String resendEmails(List<String> accountIdList) {
      String response = null;
      try {
      //Only send emails if user is either an ARMS Administor or System Administrator
      if (System.label.ARMS_Administrator_Profile_Id == userinfo.getProfileId() ||
      sysAdmin.Id == userinfo.getProfileId()) {
      List<Account> accList = [SELECT Id,FCA_Dealership__c,Branch_Manager__c,Business_Development_Manager__c,Client_Released__c,Existing_Participant__c,
      Dealership_Partner__c,Dealership_State__c,RecordTypeId,owner.email,owner.Supervisor_Email__c,Client_Number__c,Closing_Manager__r.name,
      Name,Completed_Date__c,Effective_Date__c,Closing_Manager__c,Is_the_client_receiving_compensation__c,Is_a_broker_receiving_compensation__c,Broker__r.name,
      ,Broker__r.State__c, Email_Sent__c,
      FROM Account
      WHERE Id IN:accountIdList];

      for(Account acc: accList){
      if (acc.Client_Number__c != null && acc.Client_Released__c && acc.Email_Sent__c == true) {
      sendpdfgenerationEmails(acc);
      acc.Email_Sent__c = false;

      response = 'Email Sent';
      }else {
      response= 'Access Denied';
      }
      }

      update accList;
      }
      }catch(Exception e) {
      System.debug(e.getMessage());
      response = 'Error sending emails';
      }
      return response;
      }//what this method does is call the sendpdfgeneration method which is the method that generates and sends a custom email. After calling the method, the email_sent__c field is updated to false


      Any help in fixing my test method would be greatly appreciated. Thank you










      share|improve this question














      I have written an Apex Batch schedulable class that runs a method from another class everyday at a certain time. What this batch class does is see all the accounts that have a field "Email Sent__c" as true and if it is true, it will pass those clients to the execute function so that it runs a method from a different class. this method basically generates an email and sends it. Once the email is sent, it updates the field Email_Sent__c to false. Everything works great and now in order to deploy it, I am writing some test classes. The problem is that the test class I have written for the Batch Apex only shows 50% coverage. Can someone please let me know why this is only 50% and what I can do to fix it? Also, I dont think the system.assert calls are checking the email_sent values after the update, they are only taking the values from the test setup method



      Here is the Batch Apex class I wrote:
      global class ConfirmationCardBatchApex implements Database.Batchable, Database.Stateful {
      global Database.QueryLocator start(Database.BatchableContext BC) {
      Datetime clientReleasedDate = Datetime.now().addHours(-24);



          return Database.getQueryLocator(
      'SELECT Id, Client_Released__c, Client_Number__c, Release_Date__c, ' +
      'Email_Sent__c FROM Account ' +
      'WHERE Email_Sent__c = true AND Client_Released__c = true AND Release_Date__c<=:clientReleasedDate'
      );


      }
      global void execute( Database.BatchableContext BC, List<Account> scope){
      List<String> acctIdList = new List<String>();
      for(Account account : scope){
      acctIdList.add(account.Id);

      }
      LM_ChangeAccountRT.resendEmails(acctIdList);
      } //this block of code, the execute method keeps on showing that its uncovered by my testclass!!!

      global void finish(Database.BatchableContext bc){
      System.debug( 'finish: called' );
      }


      }



      The test class I wrote is the following (I am sure it has alot of mistakes. what can i do to get 100% coverage?)



      @isTest
      public class TestConfirmationCardBatchApex {
      static Account client;
      static Account client1;
      static Account client2;
      static Account parentC;
      static Contact con;

      @testSetup
      Contact cont1 = new Contact(LastName='ContTest1', Email='test1contact@libertymutual.com', CommunicationType__c ='Holiday card', recordTypeId = Schema.SObjectType.contact.getRecordTypeInfosByName().get('Business Development Manager').getRecordTypeId(),FirstName= 'Contact');
      insert cont1;

      id tempuser = [Select id from User where LastName='Testing' limit 1].id;
      system.debug('11111'+tempuser);
      parentC = TestDataUtils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
      parentC.Dealership_Partner__c = 'BMW';
      parentC.Dealership_State__c='WA';
      parentC.Name = 'Parent Name';
      parentC.Client_Number__c = '12302.0';
      parentC.Business_Development_Manager__c=cont1.id;
      insert parentC;

      client1 = TestDataUTils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
      client1.Name = 'Test Client 2';
      client1.Business_Development_Manager__c=cont1.id;
      client1.Branch_Manager__c = tempuser;
      client1.Dealership_Partner__c = 'BMW';
      client1.Dealership_State__c= 'TX';
      client1.ParentID = parentC.Id;
      client1.Client_Number__c = '12322.0';
      client1.Email_Sent__c = true;
      client1.Client_Released__c = true;
      accountdata.add(client1);

      client2 = TestDataUTils.createAccountFromRecordType(Schema.SObjectType.Account.getRecordTypeInfosByName().get('Referral Program - Participant Form').getRecordTypeId());
      client2.Name = 'Test Client 3';
      client2.Business_Development_Manager__c=cont1.id;
      client2.Branch_Manager__c = tempuser;
      client2.Dealership_Partner__c = 'BMW';
      client2.Dealership_State__c= 'CA';
      client2.ParentID = parentC.Id;
      client2.Client_Number__c = '12332.0';
      client2.Email_Sent__c = true;
      client2.Client_Released__c = true;
      accountdata.add(client2);
      insert accountdata;
      static testmethod void test() {
      Test.startTest();
      ConfirmationCardBatchApex confirm = new ConfirmationCardBatchApex();
      Id batchId = Database.executeBatch(confirm);
      Account emailTest = [SELECT Id, Name, Client_Released__c, Client_Number__c, Release_Date__c, Email_Sent__c FROM Account WHERE Name IN ('ContTest1', 'Test Client 1', 'Test Client 2') AND Email_Sent__c = true];
      Test.stopTest();
      System.assertEquals(true, emailTest.Email_Sent__c, 'Expected value should be true'); // After method is run, the email_sent__c should be false but it only shows success when I assert it to true.
      }

      }


      In case you are wondering what this resendemails method is(in the LM_CHANGEACCOUNTRT Class), here is a snippet of it:



      @AuraEnabled
      public static String resendEmails(List<String> accountIdList) {
      String response = null;
      try {
      //Only send emails if user is either an ARMS Administor or System Administrator
      if (System.label.ARMS_Administrator_Profile_Id == userinfo.getProfileId() ||
      sysAdmin.Id == userinfo.getProfileId()) {
      List<Account> accList = [SELECT Id,FCA_Dealership__c,Branch_Manager__c,Business_Development_Manager__c,Client_Released__c,Existing_Participant__c,
      Dealership_Partner__c,Dealership_State__c,RecordTypeId,owner.email,owner.Supervisor_Email__c,Client_Number__c,Closing_Manager__r.name,
      Name,Completed_Date__c,Effective_Date__c,Closing_Manager__c,Is_the_client_receiving_compensation__c,Is_a_broker_receiving_compensation__c,Broker__r.name,
      ,Broker__r.State__c, Email_Sent__c,
      FROM Account
      WHERE Id IN:accountIdList];

      for(Account acc: accList){
      if (acc.Client_Number__c != null && acc.Client_Released__c && acc.Email_Sent__c == true) {
      sendpdfgenerationEmails(acc);
      acc.Email_Sent__c = false;

      response = 'Email Sent';
      }else {
      response= 'Access Denied';
      }
      }

      update accList;
      }
      }catch(Exception e) {
      System.debug(e.getMessage());
      response = 'Error sending emails';
      }
      return response;
      }//what this method does is call the sendpdfgeneration method which is the method that generates and sends a custom email. After calling the method, the email_sent__c field is updated to false


      Any help in fixing my test method would be greatly appreciated. Thank you







      salesforce apex






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 28 '18 at 3:27









      user3685949user3685949

      84




      84
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511662%2fsalesforce-test-class-showing-50-test-coverage-always%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53511662%2fsalesforce-test-class-showing-50-test-coverage-always%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Lallio

          Unable to find Lightning Node

          Futebolista