• uaryamarkit
  • NEWBIE
  • 0 Points
  • Member since 2010

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

I have tried and tried to write and rewrite this test class and still cannot get more than 33% coverage! Please help!!!

 

Class:

global class MVbatch implements Database.Batchable<sObject>, Schedulable
{
date myDate = date.today();

global String Query = 'Select ID, MASA_Contract_Termination_Date__c, MASA_Contract_Effective_Date__c, A1_Amount_Payable__c, A1_Validation_Frequency__c, A2_Amount_Payable__c, A2_Validation_Frequency__c,A3_Amount_Payable__c,A3_Validation_Frequency__c, A4_Amount_Payable__c,   A4_Validation_Frequency__c,A5_Amount_Payable__c,A5_Validation_Frequency__c,A6_Amount_Payable__c,A6_Validation_Frequency__c,Month_Year__c' + 'FROM Partnership_Account__c';


global Database.QueryLocator start(Database.BatchableContext bc){
return Database.getQueryLocator(Query);}

global void execute(Database.BatchableContext BC,List<sObject> scope){
    List<Partnership_Account__c> lstpaccounts = new List<Partnership_Account__c>();
    
    for(sObject s : scope){Partnership_Account__c paccount = (Partnership_Account__c)s;
        if(paccount.MASA_Contract_Termination_Date__c>= myDate && paccount.MASA_Contract_Effective_Date__c <=myDate){
                           
Marketing_Validations__c mv = new Marketing_Validations__c
(Name = paccount.Month_Year__c,
Partnership_Account__c = paccount.id,
X1_Validation_Cycle__c = paccount.C1_Validation_Frequency__c,
X2_Validation_Cycle__c = paccount.C2_Validation_Frequency__c,
X3_Validation_Cycle__c = paccount.C3_Validation_Frequency__c,
X4_Validation_Cycle__c = paccount.C4_Validation_Frequency__c,
X5_Validation_Cycle__c = paccount.C5_Validation_Frequency__c,
X6_Validation_Cycle__c = paccount.C6_Validation_Frequency__c,
X7_Validation_Cycle__c = paccount.C7_Validation_Frequency__c,
X8_Validation_Cycle__c = paccount.C8_Validation_Frequency__c,
X9_Validation_Cycle__c = paccount.C9_Validation_Frequency__c,
X10_Validation_Cycle__c =paccount.C10_Validation_Frequency__c,
X11_Validation_Cycle__c = paccount.A1_Validation_Frequency__c,
X12_Validation_Cycle__c = paccount.A2_Validation_Frequency__c,
X13_Validation_Cycle__c = paccount.A3_Validation_Frequency__c,
X14_Validation_Cycle__c = paccount.A4_Validation_Frequency__c,
X15_Validation_Cycle__c = paccount.A5_Validation_Frequency__c,
X16_Validation_Cycle__c = paccount.A6_Validation_Frequency__c,
X17_Validation_Cycle__c = paccount.A7_Validation_Frequency__c,
X18_Validation_Cycle__c = paccount.A8_Validation_Frequency__c,
X1_Amount_Payable__c= paccount.C1_Amount_Payable__c,
X2_Amount_Payable__c= paccount.C2_Amount_Payable__c,
X3_Amount_Payable__c= paccount.C3_Amount_Payable__c,
X4_Amount_Payable__c= paccount.C4_Amount_Payable__c ,
X5_Amount_Payable__c= paccount.C5_Amount_Payable__c ,
X6_Amount_Payable__c= paccount.C6_Amount_Payable__c ,
X7_Amount_Payable__c= paccount.C7_Amount_Payable__c ,
X8_Amount_Payable__c= paccount.C8_Amount_Payable__c ,
X9_Amount_Payable__c= paccount.C9_Amount_Payable__c ,
X10_Amount_Payable__c= paccount.C10_Amount_Payable__c , 
X11_Amount_Payable__c= paccount.A1_Amount_Payable__c ,
X12_Amount_Payable__c= paccount.A2_Amount_Payable__c , 
X13_Amount_Payable__c= paccount.A3_Amount_Payable__c , 
X14_Amount_Payable__c= paccount.A4_Amount_Payable__c , 
X15_Amount_Payable__c= paccount.A5_Amount_Payable__c , 
X16_Amount_Payable__c= paccount.A6_Amount_Payable__c , 
X17_Amount_Payable__c= paccount.A7_Amount_Payable__c , 
X18_Amount_Payable__c= paccount.A8_Amount_Payable__c , 
HLC_Responsible_for_MASA__c= paccount.HLC_Responsible_for_MASA__c,
HLM__c= paccount.HLM__c,
DM__c= paccount.DM__c,
BDM__c= paccount.BDM_Name__c);


insert mv;
system.debug('************'  + mv.id);
}
}
}


global void finish(Database.BatchableContext BC)
{
}

global void execute(SchedulableContext sc)
{
}
}

 Test Class:

@isTest
private class testmvbatch{

  
    static testmethod void test() {
  
        String query = 'Select ID, MASA_Contract_Termination_Date__c, MASA_Contract_Effective_Date__c, A1_Amount_Payable__c, Month_Year__c'  + 
        'FROM Partnership_Account__c' + 'WHERE MASA_Contract_Termination_Date__c <= today()';
        
        Partnership_Account__c[] palist = new List<Partnership_Account__c>();
        for (integer i=0; i<10;i++)  {
            Partnership_Account__c pa = new Partnership_Account__c (Name = 'testaccount' + i, MASA_Contract_Termination_Date__c = date.today(), MASA_Contract_Effective_Date__c = date.today(), A1_Amount_Payable__c = 123.45);
            palist.add(pa);
            }
            insert palist;    
    
        test.startTest();
        mvbatch mb=new mvbatch();
        database.executebatch(mb,200);
        test.stopTest();
        

     
     }
}

 

 

Any help would be REALLY appreciated!! Thanks!!

Hello again.

 

Well everybody`s know about the SimpleDateFormat class in Java, i'm looking for something like it in the Apex Code.

 

 

What i need to do is:

 

I ll receive an set of String containing some formated Datas like it "10/2010".

I want to iterate over this set and convert any String to Date and populate one List<Date>.

 

Tks for everything!