• Riojin
  • NEWBIE
  • 25 Points
  • Member since 2012

  • Chatter
    Feed
  • 1
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 4
    Replies

I am a newbie and I find the code coverage very difficult, if anyone can help me, would be grateful, 

 

This is the class.

 

 

global class ScheduledProducts implements Schedulable {
global void execute(SchedulableContext SC){

Datetime fivedays = DateTime.now().addDays(-5);

List<Products__c> lastDays=
[SELECT Is_Approved__c, CreatedDate FROM Products__c
WHERE CreatedDate <: fivedays AND Is_Approved__c = false];

for(Products__c a : lastDays){
if(a.Is_Approved__c == false) {
a.Is_Approved__c = true;
}
       } 
   }
}

 

Thanks in advance!

global class EmailTemplate implements Messaging.InboundEmailHandler {

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

Products er = new Products__c();

String[] values = email.plainTextBody.split(',');
er.Contact__c = values[0];

String s = values[1];
Integer i = (Integer.valueof(s.trim()));
er.Amount__c = i;

String dt = values[2];
String[] stringDate = dt.split('/');
Integer m = Integer.valueOf(stringDate[0]);
Integer d = Integer.valueOf(stringDate[1]);
Integer y = Integer.valueOf(stringDate[2]);
Date product = date.newInstance(y,m,d);
er.Date__c = product;

er.Type__c = values[3];

er.Description__c = values[4];
er.Comments__c = values[5];

insert er;

return result;

 

Thanks in advance!

I am a newbie and I find the code coverage very difficult, if anyone can help me, would be grateful, 

 

This is the class.

 

 

global class ScheduledProducts implements Schedulable {
global void execute(SchedulableContext SC){

Datetime fivedays = DateTime.now().addDays(-5);

List<Products__c> lastDays=
[SELECT Is_Approved__c, CreatedDate FROM Products__c
WHERE CreatedDate <: fivedays AND Is_Approved__c = false];

for(Products__c a : lastDays){
if(a.Is_Approved__c == false) {
a.Is_Approved__c = true;
}
       } 
   }
}

 

Thanks in advance!

global class EmailTemplate implements Messaging.InboundEmailHandler {

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

Products er = new Products__c();

String[] values = email.plainTextBody.split(',');
er.Contact__c = values[0];

String s = values[1];
Integer i = (Integer.valueof(s.trim()));
er.Amount__c = i;

String dt = values[2];
String[] stringDate = dt.split('/');
Integer m = Integer.valueOf(stringDate[0]);
Integer d = Integer.valueOf(stringDate[1]);
Integer y = Integer.valueOf(stringDate[2]);
Date product = date.newInstance(y,m,d);
er.Date__c = product;

er.Type__c = values[3];

er.Description__c = values[4];
er.Comments__c = values[5];

insert er;

return result;

 

Thanks in advance!

I am new to apex and built an apex schedule class that runs everyday. If the account review date for commisions is two weeks (14 days) away the scheduler will send an email to our Sales Department.

I have scheduled the class through the apex scheduler (NOT system.schedule)

How do I test my code?

Here is my schedulable class:

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

sendEmail();

}
public void sendEmail()
{


for(Account acc : [SELECT Id FROM Account WHERE Next_Account_Review_Date__c = : system.Today().addDays(14)])
{
Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
mail.setTemplateId('00XF0000000LfE0');
mail.setTargetObjectId('005J0000000JWYx');
Messaging.sendEmail(new Messaging.SingleEmailMessage[] {mail });
}
}
}

To test the class would it be:

test.starttest();
AccountReviewSchedulerOtherObjectID sco = new scheduledCreateOpportunity();
test.stopTest();

If so, where would I put this class (what would I call it) and how would I schedule it?

 

Though my schedule class has a submited, start and next scheduled run on "Scheduled Apex Jobs"......no email is sent out. How do I test if the email method works? The test class? 

 

What exactly does a test class do besides providing test coverage?