+ Start a Discussion
Brad BothBrad Both 

Apex Class unable to Deploy

Hey all, fairly new to Salesforce and Apex. So I'm trying to create a class that will store all the data from the parent object and the 3 child objects. I'll be using this controller in VisualForce to create PDFs with the fields collected in the class. Here is the full class (This was based on another class roughly doing the same thing, which may be where my problem is). It is failing 4 Apex tests when deployed. Thanks for the help, and apologies if this has a simple solution I'm just not seeing!


public with sharing class Program_Controller {

public Program__c myProgram{get;set;}

public Program_Controller(){
    myProgram=new Program__c();
        myProgram=[SELECT   Name, 
                                                    (SELECT Name, 
                                                    FROM Program_Toggles__r),
                                                    (SELECT Name, 
                                                    FROM Program_IOs__r),
                                                    (SELECT Name, 
                                                    FROM Program_Details__r)
                            FROM PROGRAM__c p
                            WHERE p.Id=:ApexPages.currentPage().getParameters().get('id')];
}//end of class


Here are the 4 errors I'm getting:

CalculateBusinessHoursAgesTest || testBusinessHoursBucketer || System.Exception: Assertion Failed 
Stack Trace: Class.CalculateBusinessHoursAgesTest.testBusinessHoursBucketer: line 29, column 1

Catalog_Controller_Test || runTest || System.DmlException: Insert failed. First exception on row 0; first error: FIELD_CUSTOM_VALIDATION_EXCEPTION, Carrier can not be North America for overseas shipments.: [Preferred_Carrier__c] 
Stack Trace: Class.Catalog_Controller_Test.runTest: line 32, column 1

Milestone1_Test_Field_Values || testFieldValues || System.AssertException: Assertion Failed: Expected: -1789.690000000000000000000000000000000001, Actual: -1789.69 
Stack Trace: Class.Milestone1_Test_Field_Values.testFieldValues: line 245, column 1

OppPusherTests || myOppUnitTest || System.DmlException: Insert failed. First exception on row 0; first error: CANNOT_INSERT_UPDATE_ACTIVATE_ENTITY, Opportunity_SetPricebook: execution of BeforeInsert caused by: System.NullPointerException: Attempt to de-reference a null object Trigger.Opportunity_SetPricebook: line 16, column 1: [] 
Stack Trace: Class.OppPusherTests.createOppty: line 73, column 1 Class.OppPusherTests.myOppUnitTest: line 30, column 1

Yury BondarauYury Bondarau
Hi Brad,

I would be also good to see the code of test classes. I will try to explain the issues
1 - Assertion failed in CalculateBusinessHoursAgesTest.testBusinessHoursBucketer(line 29) - There is a System.assert() method that compares actual and expected results of test execution. In case expected result is not equal to actual result System.assert throws an error.

2 - You have custom validation rule on your org that does not allow to set some values for certain field: https://help.salesforce.com/HTViewHelpDoc?id=fields_about_field_validation.htm

3 - The same as 1st but also problem can be in the number of decimal places. 

4 - There is a trigger named Opportunity_SetPricebook. For some reasons in this trigger you try to access property of null-Object. You need to check if object is NULL before trying to access a property ot the object