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
SeattleSFDCSeattleSFDC 

Deploying to Production Issues

Hello,

 

I'm having issues with deploying changes to Production, and the error messages I'm recieving is "System.NullPointerException: Attempt to de-reference a null object".  Any ideas how to fix?

 

 

Test Failures:
Hide Section - approveDealRegVFTESTapproveDealRegVFTEST
Method NameTotal Time (ms)MessageStack Trace
approveDealRegVFTEST.siApprove3818.0System.NullPointerException: Attempt to de-reference a null objectClass.approveDealRegVFTEST.siApprove: line 482, column 1
approveDealRegVFTEST.productApprove4964.0System.NullPointerException: Attempt to de-reference a null objectClass.approveDealRegVFTEST.productApprove: line 252, column 1
Hide Section - RenewalNotificationControllerTEST
 
 RenewalNotificationControllerTEST
Method NameTotal Time (ms)MessageStack Trace
RenewalNotificationControllerTEST.testRenewalNotifications11992.0System.NullPointerException: Attempt to de-reference a null objectClass.RenewalNotificationController.mergeExistingFields: line 321, column 1 Class.RenewalNotificationController.mergeAndCreateMail: line 227, column 1 Class.RenewalNotificationController.sendMail: line 177, column 1 Class.RenewalNotificationControllerTEST.testRenewalNotifications: line 71, column 1

 

approveDealRegVFTest class Line 252:

 

String retURL = controller.save().getUrl();

 

approveDealRegVFTest class Line 482:

 

String retURL = controller.save().getUrl();

 

RenewalNotificationController class line 321:

    private String mergeExistingFields(String text, Opportunity opp) {
            Set<String> existingFields = opportunityFields.keySet();
            for (String mergeField : existingFields) {
                System.debug('mergeField = ' + mergeField);
                Integer index = text.indexOf(mergeField);
                while (index != -1) {
                    String fieldSoqlName = opportunityFields.get(mergeField);
                    String value = '';

                    if (fieldSoqlName.startsWith('Account')) {
                        Account a = opp.Account;
                        fieldSoqlName = fieldSoqlName.substring(8);
                        value = (String) a.get(fieldSoqlName); <-------LINE 321
                    }

 

RenewalNotificationController Class line 227:

        //merge existing fields
        String subject = emailTemplate.Subject;
        subject = mergeExistingFields(subject, opp);       <-----LINE 227

 

RenewalNotificationController Class line 177:

                //create the merged email and add it array
                Messaging.SingleEmailMessage mail = mergeAndCreateMail(templateDetails, wrapper.getOpportunity());     <------LINE 177
                mails.add(mail);

 

RenewalNotificationControllerTEST Test Class line 71:

 

    controller.sendMail();

 

 

 
Jia HuJia Hu
In line 321, when you use a.get(fieldSoqlName);

Make sure, the 'fieldSoqlName' field on Account is null.
crop1645crop1645

In addition to Jia's remarks that point at flawed code, a larger issue is why this is happening in PROD and not in sandbox.

 

The most likely cause is your testmethods are making an assumption about the dataset they reference in any SOQL statement; especially if you are using testmethods at V23.0 or earlier or @isTest(seeAllData=true) annotation

 

When you run testmethods in sandbox, the SOQL calls will only fetch data known in Sandbox; but when you deploy, the same testmethods have available the full database in PROD to fetch from. Thus, the test execution contexts aren't in perfect fidelity

 

Best practice on testmethods is to only fetch sobjects that the testmethods create and no others