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
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();
    
    if(ApexPages.currentPage().getParameters().get('id')!=null){
        myProgram=[SELECT   Name, 
                                                    Active__c, 
                                                    Alpha_Test__c, 
                                                    Base_Program__c, 
                                                    Beta_Test__c, 
                                                    Bootloader__c, 
                                                    Complexity__c, 
                                                    Description__c, 
                                                    Design_Approval__c, 
                                                    Design_Finalized__c, 
                                                    Electrical_System__c, 
                                                    Engineering_Documentation_Review__c, 
                                                    Estimated_Completion__c,
                                                    Field_test_Required__c, 
                                                    Final_Test__c, 
                                                    Program_ID__c, 
                                                    Sales_Documentation_Review__c, 
                                                    Sales_R_C_Review__c, 
                                                    Short_Descrip__c, 
                                                    Status_Reason__c, 
                                                    Sticker__c, 
                                                    (SELECT Name, 
                                                        Active__c,
                                                        Jumper_Position__c,
                                                        MSID__c,
                                                        Toggle__c,
                                                        ToggleDisp__c,
                                                        Toggle_State__c              
                                                    FROM Program_Toggles__r),
                                                    (SELECT Name, 
                                                        Active__c,
                                                        Duration__c,
                                                        Function__c,
                                                        FunctionDisp__c,
                                                        MSID__c,
                                                        Signal__c,
                                                        SignalDisplay__c,
                                                        Wire__c              
                                                    FROM Program_IOs__r),
                                                    (SELECT Name, 
                                                        Active__c,
                                                        Jumper_Position__c,
                                                        MSID__c,
                                                        TypeDisp__c,
                                                        Value__c,
                                                        Variable__c,
                                                        VariableDisp__c              
                                                    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.
http://salesforce.stackexchange.com/questions/55386/how-do-i-use-system-assert-system-assertequals-system-run-as-in-my-unit-test

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