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
rao6308rao6308 

urgent help with test method

Experts

 

Please help me find my mistake in the following test method :

 

main class method :
    public PageReference savenew()
    {   
        multi_deal__c savenewrec = new multi_deal__c
            (    
               /* name                         = multinew.name,
                unit_buy_price__c            = multinew.unit_buy_price__c,
                opportunity__c               = CurrentId,
                unit_sell_price__c           = multinew.unit_sell_price__c,
                global_sfdc_category__c      = multinew.global_sfdc_category__c,
                //unit_value__c              = fixFormatting(unitval)
                unit_value__c                = multinew.unit_value__c,
                global_sfdc_subcategory_1__c = multinew.global_sfdc_subcategory_1__c,
                global_sfdc_subcategory_2__c = multinew.global_sfdc_subcategory_2__c */
                
                Display_order__c                         = multinew.display_order__c,
                opportunity__c                           = currentid,
                name                                     = multinew.name,
                Total_Deal_Max__c                        = multinew.Total_Deal_Max__c,
                Buyer_max__c                             = multinew.Buyer_Max__c,
                Global_SFDC_Category__c                  = multinew.Global_SFDC_Category__c,                                        
                Global_SFDC_Subcategory_1__c             = multinew.Global_SFDC_Subcategory_1__c,
                Global_SFDC_Subcategory_2__c             = multinew.Global_SFDC_Subcategory_2__c,
                unit_value__c                            = multinew.unit_value__c,
                Unit_Sell_Price__c                       = multinew.Unit_Sell_Price__c,
                Unit_buy_price__c                        = multinew.Unit_buy_Price__c,
                Alternative_Highlights__c                = multinew.Alternative_Highlights__c,
                Multi_Deal_Expiration_Date__c            = multinew.Multi_Deal_Expiration_Date__c       
            );
        Database.SaveResult SR = database.insert(savenewrec);
        if(sr.isSuccess())
        {
            ApexPages.Message myMsg = new ApexPages.Message(ApexPages.Severity.info,'Multi Deal Data saved.'+ savenewrec.Id);
            ApexPages.addMessage(myMsg);
            cancelnewmode();
        }
        return null;
    }


test method :

//Inserts
 account a = new account();
                         a.name = 'test acct';
                         insert a;                       
                         
                         opportunity o = new opportunity();
                         o.name = 'test oppty';
                         o.StageName = 'Prospecting';
                         o.CloseDate = date.today();
                         o.Deal_Strengh__c = 'Rep Getting Info';
                         o.Feature_Date__c = date.newinstance(2011, 7, 15);
                         o.AccountId = a.Id;
                         insert o;                        
                         
                         //insert multi-deal
                         multi_deal__c md = new multi_deal__c(
                         Opportunity__c = o.Id,
                         name           = 'test',
                         unit_value__c  = 123);
                            
//Inserts
Test.starttest();
insert md;
Test.stoptest();
checkbox_class check = new checkbox_class();
PageReference p = Page.oppmultideals;
Test.setCurrentPageReference(p);
System.currentPageReference().getParameters().put('id',md.opportunity__c);
check.savenew(); == when i call this method i get the following error :

System.DmlException: Insert failed. First exception on row 0; first error: REQUIRED_FIELD_MISSING, Required fields are missing: [Opportunity__c]: [Opportunity__c]

Class.Checkbox_Class.savenew: line 58, column 34 Class.Checkbox_Class.createmultideal: line 308, column 3 External entry point

 

I am sure I am missing something, please help me out

 

Thanks a lot in advance.

steve456steve456

are you giving all the mandatorty fields of opportunity.Cpy the exact api name of opprtunity from multideal obj

rao6308rao6308

Hey Steve

 

Thanks for the reply. I get an error saying

Invalid field Opportunity for SObject Multi_Deal__c

 

Am I doing something wrong with the system.currentpage().getparameter().put('id')

 

I am using this VF page as a visual force inline on a standard opportunity page, should that matter ( I beleive that should not since the system thorws an "Invalid Id : test '  when I set the opportunity__c = 'test' as junk value when running the test method)

 

I even tried hardcoding one of the opportunity Id's it throws the same error " Required field missing "

 

Please help