function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
YeyericYeyeric 

Failure Message: "System.NullPointerException: Attempt to de-reference a null object", Failure Stack Trace:

Hello,

I'm trying to release a new dev made in sandbox. One of the class had already been released in prod from the sandbox but it's not blocking.

Here is the error message I get :

Failure Message: "System.NullPointerException: Attempt to de-reference a null object", Failure Stack Trace: "Class.PricerOffer.firstList: line 177, column 1 Class.PricerController_TEST.pricerControllerTest: line 52, column 1"

And here is the code of the test until some lines below the line 52:

@isTest
public class PricerController_TEST {

  // -------------------------------------
    // pricerControllerTest() method
    // ------------------------------------- 
  static testMethod void pricerControllerTest() {
    // Data Model
    PricerUtils_TEST.loadPricerData();
   
    test.startTest();
   
        PageReference oPageRef = new PageReference('/apex/Pricer?oppId=' + PricerUtils_TEST.oOpp.Id);
        test.setCurrentPageReference(oPageRef);
        PricerController oPricerController = new PricerController();
        PricerSiteOffer.bIsTest = true;
       
        system.debug(Logginglevel.ERROR, '### SFDC - PricerController_TEST - pricerControllerTest() - PricerUtils_TEST.lRV.size():' + PricerUtils_TEST.lRV.size());
   
    // Initializing  Pricer options
    oPricerController.oOfferOption.sDateDebutContrat = String.valueOf(system.today().toStartOfMonth());
    oPricerController.oOfferOption.oOffer.X12_mois__c = true;
    oPricerController.oOfferOption.oOffer.X24_mois__c = false;
    oPricerController.oOfferOption.oOffer.X36_mois__c = false;
    oPricerController.oOfferOption.oOffer.X48_mois__c = false;
    oPricerController.oOfferOption.oOffer.TECH_Duree_mois__c = '12';
    oPricerController.oOfferOption.oOffer.Cout_variable_transport__c = 'Oui';
    oPricerController.oOfferOption.oOffer.Offre_regulee__c = 'Oui';
    oPricerController.oOfferOption.oOffer.Copropriete_Clinique_Public__c = 'Oui';
    oPricerController.oOfferOption.oOffer.Assujetti_TVA__c = true;
    system.assertEquals(PricerController.bBatchSendEmail, true);
    system.assertNotEquals(PricerOption.lDateDebutContrat.size(), 0);
    system.assertNotEquals(PricerOption.sDateValiditeOffre, null);
    system.assertNotEquals(PricerOption.sDateFinMaxOffre, null); 
   
    // Execute Pricer
    oPricerController.executeBatchOrNot();
    system.assertEquals(oPricerController.oOfferOption.lOffer.size(), 2);
   
    integer i=0;
        for (PricerOffer oPricerOffer:oPricerController.lOffer){
      system.assertequals(oPricerOffer.iNbExistingSiteOffer, 3);
     
      // Save offer
            oPricerOffer.saveOffer();
           
            // Pagination functionality
            if(i==0){
              system.assertNotEquals(PricerOffer.DISPLAYSITEDETAIL, null);
              system.assertNotEquals(PricerOffer.NBSITESAVECDETAIL, null);
             
              oPricerOffer.firstList();
              oPricerOffer.nextList();
              oPricerOffer.previousList();
              oPricerOffer.lastList();
            }           
            i++;
        }

I'm not a dev but I'm surprised this is now posing problem because before it has been released ok. Also, our salesforce org hasn't changed much, although we created some unique IDs which were posing problems but I removed them and the test is now failing only at this step.

Thanks for your help

Regards,

Vinita_SFDCVinita_SFDC
Hi,

Is this the 52nd line: system.assertNotEquals(PricerOffer.NBSITESAVECDETAIL, null);

Please check if you have initialized the variable where you are getting this error. We mostly get this error if the variable is not initialized.
Amit_Amit_
Hi Yeyeric,

problem is not with the test class, Null pointer is occuring in the class:   Class.PricerOffer.firstList: line 177 at line number 177 if you can paste your class code then porbably we can help you out.

Regards,
Amit_