• Prabhat Arora
  • NEWBIE
  • 20 Points
  • Member since 2017

  • Chatter
    Feed
  • 0
    Best Answers
  • 0
    Likes Received
  • 0
    Likes Given
  • 2
    Questions
  • 3
    Replies
Hi All,
Needed a help in testing the VF Extension,  I am overiding the OLI "EDIT" button to redirect to some custom VF page, below is my controller extension & VF page used for redirecting, 
<apex:page standardController="OpportunityLineItem" extensions="redirect_Ext" 
action="{!if(rCardUploaded==TRUE,'/apex/IRC_VF?oppId='+OpptyId,URLFOR($Action.OpportunityLineItem.Edit,OpportunityLineItem.Id,[
saveURL=OpportunityLineItem.Id,retURL=OpptyId],true))}">
</apex:page>
This VF Page is redirecting to another VF Page (IRC_VF) on meeting a check box true condition.
Below is the extension Controller.
public class redirect_Ext {
    public OpportunityLineItem opptyLineItemRec;
    Public Opportunity OpptyRec;
    Public String OpptyId{get;set;}
    public Boolean rCardUploaded{get;set;}
    public redirect_Ext(ApexPages.StandardController controller) {
        opptyLineItemRec = [select id, Imported_from_Rate_Card_c__c, OpportunityId from OpportunityLineItem where id =: System.currentPageReference().getParameters().get('id')];
        rCardUploaded = opptyLineItemRec.Import_from_R_Card_c__c;
        OpptyId = opptyLineItemRec.OpportunityId;

    }
}
Everything is Working perfect, I NEED HELP on Writing Test Class, as i am not able pass the pagerefernce or redirecting amongst the pages, i had created the test data, only need an understanding on how to cover testing page navigation in this scenario.
Help will be Highly appreciated.

 
Hi All, I had created a batch job, for which i am writing a test class, batch class is working fine but i am missing something in Test Class, below is the code snippet of both of my classes, my Test class is not covering the execute method of the  batch job, resulting in just 37% of code coverage. It would be a great help  if somebody can help me in figuring out the issue.
 
***********My Batch Class***********
global class CreateMissingentitlementWithSA  implements Database.Batchable<sObject> {
    
   List<String> Reclist = new List<String>{'Renewal - Booked', 'Renewal'};   
   List<String> StgVal = new List<String>{'Closed Won'};
    
   public String  Query='Select id, OpportunityId,Opportunity.stageName, Name from OpportunityLineItem where OpportunityId Not In (Select Opportunity__c From Entitlement__c)';   
 
    
 global database.querylocator start(Database.BatchableContext BC)
  {
  
  return Database.getQueryLocator(Query);
  } 
    
 global void execute(Database.BatchableContext BC, List<sObject> scope) {
    
    list<OpportunityLineItem> Opp=new list<OpportunityLineItem>();
    set<Id> Opptyids=new set<Id>();
    set<Id> OpsId=new set<Id>();
    list<opportunitylineItem> listOLIs = new list<opportunitylineItem>();
     for(sObject s : scope){
         OpportunityLineItem op = (OpportunityLineItem)s;
          if(op.id!=null){
            Opptyids.add(Op.id);
          }
          if(op.OpportunityId!=null){
            OpsId.add(op.OpportunityId);
          }
        
     }
     if(!Opptyids.isempty()){
        
        listOLIs = [SELECT OpportunityId, id,Product2id,Number_of_SAT_Hours__c,Number_of_Units__c ,PricebookEntryId FROM OpportunityLineItem where OpportunityId not in (select opportunity__c from entitlement__c) and Product2.family = 'Product Bundle' and Product2.Web_Site_Id__c!='' and id in :Opptyids];

        if(listOLIs!=null && listOLIs.size()>0)
        {
            ConvertedOLIWorkflows objConvertedOLIWorkflows = new ConvertedOLIWorkflows (listOLIs );
            objConvertedOLIWorkflows.createEntitlementAfterOLI(listOLIs );
        system.debug('Check If Entitlements Addedd Successfully');
        }
                
         list<Service_Access__c> SAlist =  new list<Service_Access__c>();   
        
         SAlist= [Select id, Sold_Opportunity__c from Service_Access__c where Sold_Opportunity__c In:OpsId];       
         Map<Id, Id> SAOptyMap = new Map<Id, Id>();
         If (SAlist!=null)
          for (Service_Access__c SA:SAlist) 
          {
          SAOptyMap.Put(SA.Sold_Opportunity__c, SA.Id);
          }
          list<Entitlement__c> EntLst = new list<Entitlement__c>();
          EntLst= [Select id, Opportunity__c, Service_Access__c from Entitlement__c where Opportunity__c In:OpsId];
          
          for(Entitlement__c Ent:EntLst ){
          Ent.Service_Access__c= SAOptyMap.get(Ent.Opportunity__c);
          }
          
          Update EntLst;
            
            
     }
    
    
   }  
   
    global void finish(Database.BatchableContext BC){
    
   AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,
                      TotalJobItems, ExtendedStatus,CreatedBy.Email
                 from AsyncApexJob where Id =:BC.getJobId()];
              
     //Send an email to the Apex job's submitter notifying of job completion.
       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       String[] toAddresses = new String[] {a.CreatedBy.Email};
       mail.setToAddresses(toAddresses);
       mail.setBccSender(true);
       mail.setSubject('Add missing entitlements batch job ' + a.Status );
       mail.setPlainTextBody
             ('The batch Apex job processed ' + a.TotalJobItems +
           ' batches with '+ a.NumberOfErrors + ' failures due to'+ a.ExtendedStatus  );
          Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
          
          
   }
  
}
 
*******my Test Class for the above batch***
@isTest(seeAllData=true)
private class CreateMissingentitlementWithSATestClass{

    static testMethod void myTest() {
                             
          Id rtid = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewal').getRecordTypeId();

          Id rtid1 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewal - Booked').getRecordTypeId();
                      
          Product2 p = new product2(name='Test Product', Family = 'Product Bundle', Discount_No_Approval__c=10, Discount_FL_Approval__c=25, Discount_GL_Approval__c =50, Discount_Finance_Approval__c =75, Web_Site_Id__c = 'test');
          insert p;
          
          Bundled_Components__c bundComp = new Bundled_Components__c(CurrencyIsoCode='USD', Parent_Product__c=p.id);
          insert bundComp;
            
          insert new PricebookEntry(unitprice = 100.0, product2id = p.id, pricebook2id = Test.getStandardPricebookId(),isActive=true);
                                         
                
          Pricebook2 pb = new pricebook2(name='test pricebook');
          insert pb;
            
          PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=p.id, unitprice=100.0, isActive=true);
          insert pbe;  
                       
          account acc = new account(Type = 'LE', Membership_Type__c = 'Standard', AnnualRevenue = 100, Name = 'SaurabhTest', NumberOfEmployees = 2, Region__c = 'NA');
          insert acc;                             
        
          Contact c = new Contact(AccountID =acc.Id, FirstName='FirstName', LastName='Testing Contact',Title='Naveen', Email='test14@gmail1421.com', Mailing_Address_1__c='Delhi');
          insert c;
            

                         
                         opportunity oppNew = new opportunity();
                         oppNew.Gartner_Opportunity_ID__c = 'o12345'; 
                         oppNew.Amount = 0 ;
                         oppNew.Pricebook2Id = pb.id ;
                         oppNew.GTS__c = true;
                         //oppnew.TerritoryId = TerritoryId;
                         //oppnew.ownerId = OwnerId;
                         oppNew.Main_Contact__c = c.id ;
                         oppNew.accountId = acc.id;
                         oppNew.stageName = 'Prospecting';
                         oppNew.CloseDate = Date.today();
                         oppNew.Name = 'GTS Opportunity';
                         oppNew.RecordTypeId=rtid;
                                                  
                         insert oppNew;
                         
          OpportunityLineItem oli = new OpportunityLineItem(Allow_Delete__c=true, Manual_Pricing__c=true,opportunityid=oppNew.id,UnitPrice=100, quantity=1,
                                        pricebookentryid=pbe.Id,Start_Date__c=Date.newInstance(2018,03,22),End_Date__c=Date.newInstance(2019,03,21),Retail_Amount__c=550000);
                                        
          insert oli;
                         
                                             
     Test.startTest(); 
     CreateMissingentitlementWithSA ent = new CreateMissingentitlementWithSA();
     Id batchId = Database.executeBatch(ent); 
     Test.stopTest();         
        
          
   
   }
   }

 
Hi All,
Needed a help in testing the VF Extension,  I am overiding the OLI "EDIT" button to redirect to some custom VF page, below is my controller extension & VF page used for redirecting, 
<apex:page standardController="OpportunityLineItem" extensions="redirect_Ext" 
action="{!if(rCardUploaded==TRUE,'/apex/IRC_VF?oppId='+OpptyId,URLFOR($Action.OpportunityLineItem.Edit,OpportunityLineItem.Id,[
saveURL=OpportunityLineItem.Id,retURL=OpptyId],true))}">
</apex:page>
This VF Page is redirecting to another VF Page (IRC_VF) on meeting a check box true condition.
Below is the extension Controller.
public class redirect_Ext {
    public OpportunityLineItem opptyLineItemRec;
    Public Opportunity OpptyRec;
    Public String OpptyId{get;set;}
    public Boolean rCardUploaded{get;set;}
    public redirect_Ext(ApexPages.StandardController controller) {
        opptyLineItemRec = [select id, Imported_from_Rate_Card_c__c, OpportunityId from OpportunityLineItem where id =: System.currentPageReference().getParameters().get('id')];
        rCardUploaded = opptyLineItemRec.Import_from_R_Card_c__c;
        OpptyId = opptyLineItemRec.OpportunityId;

    }
}
Everything is Working perfect, I NEED HELP on Writing Test Class, as i am not able pass the pagerefernce or redirecting amongst the pages, i had created the test data, only need an understanding on how to cover testing page navigation in this scenario.
Help will be Highly appreciated.

 
Hi All, I had created a batch job, for which i am writing a test class, batch class is working fine but i am missing something in Test Class, below is the code snippet of both of my classes, my Test class is not covering the execute method of the  batch job, resulting in just 37% of code coverage. It would be a great help  if somebody can help me in figuring out the issue.
 
***********My Batch Class***********
global class CreateMissingentitlementWithSA  implements Database.Batchable<sObject> {
    
   List<String> Reclist = new List<String>{'Renewal - Booked', 'Renewal'};   
   List<String> StgVal = new List<String>{'Closed Won'};
    
   public String  Query='Select id, OpportunityId,Opportunity.stageName, Name from OpportunityLineItem where OpportunityId Not In (Select Opportunity__c From Entitlement__c)';   
 
    
 global database.querylocator start(Database.BatchableContext BC)
  {
  
  return Database.getQueryLocator(Query);
  } 
    
 global void execute(Database.BatchableContext BC, List<sObject> scope) {
    
    list<OpportunityLineItem> Opp=new list<OpportunityLineItem>();
    set<Id> Opptyids=new set<Id>();
    set<Id> OpsId=new set<Id>();
    list<opportunitylineItem> listOLIs = new list<opportunitylineItem>();
     for(sObject s : scope){
         OpportunityLineItem op = (OpportunityLineItem)s;
          if(op.id!=null){
            Opptyids.add(Op.id);
          }
          if(op.OpportunityId!=null){
            OpsId.add(op.OpportunityId);
          }
        
     }
     if(!Opptyids.isempty()){
        
        listOLIs = [SELECT OpportunityId, id,Product2id,Number_of_SAT_Hours__c,Number_of_Units__c ,PricebookEntryId FROM OpportunityLineItem where OpportunityId not in (select opportunity__c from entitlement__c) and Product2.family = 'Product Bundle' and Product2.Web_Site_Id__c!='' and id in :Opptyids];

        if(listOLIs!=null && listOLIs.size()>0)
        {
            ConvertedOLIWorkflows objConvertedOLIWorkflows = new ConvertedOLIWorkflows (listOLIs );
            objConvertedOLIWorkflows.createEntitlementAfterOLI(listOLIs );
        system.debug('Check If Entitlements Addedd Successfully');
        }
                
         list<Service_Access__c> SAlist =  new list<Service_Access__c>();   
        
         SAlist= [Select id, Sold_Opportunity__c from Service_Access__c where Sold_Opportunity__c In:OpsId];       
         Map<Id, Id> SAOptyMap = new Map<Id, Id>();
         If (SAlist!=null)
          for (Service_Access__c SA:SAlist) 
          {
          SAOptyMap.Put(SA.Sold_Opportunity__c, SA.Id);
          }
          list<Entitlement__c> EntLst = new list<Entitlement__c>();
          EntLst= [Select id, Opportunity__c, Service_Access__c from Entitlement__c where Opportunity__c In:OpsId];
          
          for(Entitlement__c Ent:EntLst ){
          Ent.Service_Access__c= SAOptyMap.get(Ent.Opportunity__c);
          }
          
          Update EntLst;
            
            
     }
    
    
   }  
   
    global void finish(Database.BatchableContext BC){
    
   AsyncApexJob a = [Select Id, Status, NumberOfErrors, JobItemsProcessed,
                      TotalJobItems, ExtendedStatus,CreatedBy.Email
                 from AsyncApexJob where Id =:BC.getJobId()];
              
     //Send an email to the Apex job's submitter notifying of job completion.
       Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();
       String[] toAddresses = new String[] {a.CreatedBy.Email};
       mail.setToAddresses(toAddresses);
       mail.setBccSender(true);
       mail.setSubject('Add missing entitlements batch job ' + a.Status );
       mail.setPlainTextBody
             ('The batch Apex job processed ' + a.TotalJobItems +
           ' batches with '+ a.NumberOfErrors + ' failures due to'+ a.ExtendedStatus  );
          Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });
          
          
   }
  
}
 
*******my Test Class for the above batch***
@isTest(seeAllData=true)
private class CreateMissingentitlementWithSATestClass{

    static testMethod void myTest() {
                             
          Id rtid = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewal').getRecordTypeId();

          Id rtid1 = Schema.SObjectType.Opportunity.getRecordTypeInfosByName().get('Renewal - Booked').getRecordTypeId();
                      
          Product2 p = new product2(name='Test Product', Family = 'Product Bundle', Discount_No_Approval__c=10, Discount_FL_Approval__c=25, Discount_GL_Approval__c =50, Discount_Finance_Approval__c =75, Web_Site_Id__c = 'test');
          insert p;
          
          Bundled_Components__c bundComp = new Bundled_Components__c(CurrencyIsoCode='USD', Parent_Product__c=p.id);
          insert bundComp;
            
          insert new PricebookEntry(unitprice = 100.0, product2id = p.id, pricebook2id = Test.getStandardPricebookId(),isActive=true);
                                         
                
          Pricebook2 pb = new pricebook2(name='test pricebook');
          insert pb;
            
          PricebookEntry pbe = new PricebookEntry(pricebook2id=pb.id, product2id=p.id, unitprice=100.0, isActive=true);
          insert pbe;  
                       
          account acc = new account(Type = 'LE', Membership_Type__c = 'Standard', AnnualRevenue = 100, Name = 'SaurabhTest', NumberOfEmployees = 2, Region__c = 'NA');
          insert acc;                             
        
          Contact c = new Contact(AccountID =acc.Id, FirstName='FirstName', LastName='Testing Contact',Title='Naveen', Email='test14@gmail1421.com', Mailing_Address_1__c='Delhi');
          insert c;
            

                         
                         opportunity oppNew = new opportunity();
                         oppNew.Gartner_Opportunity_ID__c = 'o12345'; 
                         oppNew.Amount = 0 ;
                         oppNew.Pricebook2Id = pb.id ;
                         oppNew.GTS__c = true;
                         //oppnew.TerritoryId = TerritoryId;
                         //oppnew.ownerId = OwnerId;
                         oppNew.Main_Contact__c = c.id ;
                         oppNew.accountId = acc.id;
                         oppNew.stageName = 'Prospecting';
                         oppNew.CloseDate = Date.today();
                         oppNew.Name = 'GTS Opportunity';
                         oppNew.RecordTypeId=rtid;
                                                  
                         insert oppNew;
                         
          OpportunityLineItem oli = new OpportunityLineItem(Allow_Delete__c=true, Manual_Pricing__c=true,opportunityid=oppNew.id,UnitPrice=100, quantity=1,
                                        pricebookentryid=pbe.Id,Start_Date__c=Date.newInstance(2018,03,22),End_Date__c=Date.newInstance(2019,03,21),Retail_Amount__c=550000);
                                        
          insert oli;
                         
                                             
     Test.startTest(); 
     CreateMissingentitlementWithSA ent = new CreateMissingentitlementWithSA();
     Id batchId = Database.executeBatch(ent); 
     Test.stopTest();         
        
          
   
   }
   }