+ Start a Discussion
Guru 91Guru 91 

Help with test class for batch apex?

Hi,
Help me with test class

public with sharing class CDP_Deal_BookmarkAfterUpdateHandler extends TriggerHandlerBase{
    Map<Id, CDP_Deal_Bookmark__c> qualifiedBookmarks;

    public override void qualifyStartingRecords(List<sObject> newList, List<sObject> oldList, Map<ID, sObject> newMap, Map<ID, sObject> oldMap) {
        // everything qualifies for the CDPService.createFieldTrackingFeeds method
        CDPService.createFieldTrackingFeeds(newMap, oldMap, 'Deal__c', true);
    }

    public override void start() {

    }

    public override void finish(boolean fromStart){}
}
Raj VakatiRaj Vakati
Try this
 
@isTest
public class CDP_Deal_BookmarkAfterUpdateHandlerTest {
    @isTest static void check(){
		//Set all the data .. 
        list<CDP_Deal_Bookmark__c> c=new list<CDP_Deal_Bookmark__c>();
        for(integer i=0;i<200;i++){
            CDP_Deal_Bookmark__c g=new CDP_Deal_Bookmark__c();
            
            g.Name='ABSYZ';
            c.add(g);
        }
        insert c;
           
  Test.startTest();
      CDP_Deal_BookmarkAfterUpdateHandler  x = new CDP_Deal_BookmarkAfterUpdateHandler ();
     
    Test.stopTest();
    }
}

 
Guru 91Guru 91
Hi Raj,
It covered Zero Percentage.

Here is my updated code 

@isTest
public class CDP_Deal_BookmarkAfterUpdateHandlerTest {
    
        
    @isTest static void check(){
         CDP_Deal__c deal = new CDP_Deal__c();
        deal.Name = 'Test Deal';
        insert deal;
        system.debug('------deal----'+deal.Id);
        list<CDP_Deal_Bookmark__c> c=new list<CDP_Deal_Bookmark__c>();
        for(integer i=0;i<200;i++){
            CDP_Deal_Bookmark__c g=new CDP_Deal_Bookmark__c();
            g.Deal__c=deal.Id;
            c.add(g);
        }
        insert c;
           
  Test.startTest();
      CDP_Deal_BookmarkAfterUpdateHandler  x = new CDP_Deal_BookmarkAfterUpdateHandler ();
    
    Test.stopTest();
    }
}
Raj VakatiRaj Vakati
where you are using this class CDP_Deal_BookmarkAfterUpdateHandler ? can you give me the main class