• Cody Drennon
  • NEWBIE
  • 10 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 0
    Replies
Hello, 
So i have a user interface that has a month picklist and a year picklist.  Each one is hardcoded with months and years and each one has an Id.  There are only 4 years in the years picklist and all 12 months in the month picklist.  My questions is, can these be validated for example, make sure that the end date and no greater than one year after the start date.  I have been trying to figure out a way to do this for over a day now and just cant seem to figure out any logic for this.  If anyone could please let me know if this is even possible i would greatly appreciate it.  Thank you.  This is using a custom apex page, and angular2 font end.
Hello, I am trying to write a test class for the following batch class but cant seem to get past the first select statement in the soql query.  Below class is my current test class.  Any help would be great.  Thanks!

BATCH CLASS
********************************************************************************************************************************/

global class ATS_CCCAPAuthRollUpBatch implements Database.Batchable<sObject>,Database.stateful,Schedulable{
    
    public integer counter = 0;   
    public Boolean validFiscAgree = false;
    
    global Database.QueryLocator start(Database.BatchableContext BC) {
        return Database.getQueryLocator('SELECT Id, (SELECT Id, Fiscal_Agreement_Valid__c, CI_Effective_Begin_Date__c, CI_Effective_End_Date__c  FROM CCCAP_Authorization__r WHERE LastModifiedDate >= YESTERDAY OR CreatedDate >= YESTERDAY), ' + 
                                        '(Select Id, Status__c From Fiscal_Agreement_Details__r WHERE CreatedDate >= YESTERDAY OR LastModifiedDate >= YESTERDAY OR CI_Effective_Begin_Date__c = TODAY OR CI_Effective_End_Date__c < TODAY) ' +
                                        'FROM County__c WHERE Id IN (SELECT Provider_County__c FROM Fiscal_Agreement_Details__c WHERE CreatedDate >= YESTERDAY ' + 
                                        'OR LastModifiedDate >= YESTERDAY OR CI_Effective_Begin_Date__c = TODAY OR CI_Effective_End_Date__c < TODAY)');   
        
       
    }
    
    global void execute(Database.BatchableContext BC, List<County__c> scope){
        List<CCCAP_Authorization__c> authList = new List<CCCAP_Authorization__c>();
        
         system.debug('********************* THIS IS THE Execute METHOD');

        system.debug('THIS IS THE SCOPE OBJECT.........COUNTY_C ' + scope);        
        
        for(County__c county : scope){ 
            for(CCCAP_Authorization__c auth : county.CCCAP_Authorization__r) {
                for(Fiscal_Agreement_Details__c fiscal : county.Fiscal_Agreement_Details__r) {
                    if(fiscal.Status__c == 'Active' && !auth.Fiscal_Agreement_Valid__c && auth.CI_Effective_Begin_Date__c <= date.TODAY() && auth.CI_Effective_End_Date__c > date.TODAY() )
                    {  
                        auth.Fiscal_Agreement_Valid__c = true;
                        authList.add(auth);
                        counter++;
                    }
                    else if(auth.Fiscal_Agreement_Valid__c && (fiscal.Status__c != 'Active' || auth.CI_Effective_Begin_Date__c > date.TODAY() || auth.CI_Effective_End_Date__c < date.TODAY())) 
                    {
                        auth.Fiscal_Agreement_Valid__c = false;
                        authList.add(auth);
                        counter++;
                    }   
                }
            }   
        }
        if(!authList.isEmpty()){
            system.debug('AuthList' + authList);
            update authList;
        }
    } 
    
    global void finish(Database.BatchableContext BC) {
        system.debug('The batch has successfully updated ' + counter + ' records');
    }
    
    global void execute(SchedulableContext sc){
        ATS_CCCAPAuthRollUpBatch arb = new ATS_CCCAPAuthRollUpBatch();
        database.executeBatch(arb,100);
    }
    
}

________________________________________________________________
TEST CLASS

@isTest
public class ATS_CCCAPAuthRollUpBatch_Test {
    
   @isTest
    static void testAuthBatch() {
        
        County__c c = new County__c();
         CCCAP_Authorization__c auth = new CCCAP_Authorization__c();
        
        auth.County__c = c.id;
        
        auth.Fiscal_Agreement_Valid__c = true;
        auth.CI_Effective_Begin_Date__c = date.valueOf('2017-04-12');
        auth.CI_Effective_End_Date__c = date.valueOf('2019-09-12');
        auth.CreatedDate= date.valueOf('2018-04-18');
        auth.LastModifiedDate = date.valueOf('2018-04-18');
        
        Fiscal_Agreement_Details__c fad = new Fiscal_Agreement_Details__c();
        fad.Provider_County__c = c.id;
        
        fad.CI_Effective_Begin_Date__c = date.valueOf('2017-04-12');
        fad.CI_Effective_End_Date__c = date.valueOf('2019-09-12');
        fad.CreatedDate= date.valueOf('2018-04-18');
        
        List<CCCAP_Authorization__c> authList = new List<CCCAP_Authorization__c>();
       
        
        
        Test.startTest();
        ATS_CCCAPAuthRollUpBatch arb = new ATS_CCCAPAuthRollUpBatch();
        Database.executeBatch(arb);
        Test.stopTest();
        
        
    }

}