function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
AngelikaAngelika 

23% test coverage, please help! Salesforce does not recognize the calling of my method.

Hi, I have created an Apex Scheduler Class that sends an email 14 days before an account review date. It's working fine in production, but I don't have enough code coverage. Salesforce seems to think that I am not calling the sendAccountEmail method.....when I am!

 

Here is the code:

 

global class AccountEmail implements Schedulable{ 
global void execute (SchedulableContext ctx) 


sendAccountEmail(); 

}
public void sendAccountEmail()


{

 OrgWideEmailAddress Orgid = [Select Id,displayname from OrgWideEmailAddress]; 

    for(Account acc : [SELECT Id, Commission_Name__c FROM Account WHERE Next_Account_Review_Date__c = : system.Today().addDays(14)])
 
  {
  
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage(); 

String[] toAddresses = new String[] {'amodawal@projetech.com'}; 

mail.setToAddresses(toAddresses);

 mail.setOrgWideEmailAddressId(Orgid.Id);  


mail.setsubject('Account Reminder');
mail.setHtmlBody('This is a scheduler-generated email to notify you that the Account Review Date of Name:  ' + acc.Commission_Name__c + '  is in two weeks. Please click the link to calculate commission: https://cs10.salesforce.com/flow/Organic_Commission_Determination_Flow?OldCommissionID=&vaAccountID&vaAccountID=acc.id');
mail.setSaveAsActivity(false);
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail }); 
}
}

static testMethod void myCommission() 
{

    //create the required test data needed for the test scenario
   
 //creating Account
    Account testAccount = new Account(name='DGC financial test');
    insert testAccount;
    
    
//giving the account an account review date 14 days away 
    testAccount.Original_Account_Review_Date__c=system.Today().addDays(14);
   
     AccountEmail hw = new AccountEmail ();
     hw.sendAccountEmail();
}
}
Suresh RaghuramSuresh Raghuram

23% code coverage is entire org or only this class ,

if it is only this class click on 23% (Number link) where you can see a wiziard with code covered part in white color and un covered in orange color.

 

from this you will get an idea.

 

one more ting to remind you after looking into your test code i found you are not passing all inputs required , make sure with that