You need to sign in to do that
Don't have an account?
Opportunity fields values not added in Opportunity List for writing Unit Test
I am writing test class for below code:
Global class OpportunityController{
public OpportunityController(ApexPages.StandardController controller) {
oppList = New List<Opportunity>();
op = (Opportunity )controller.getRecord();
System.debug('op----'+op);
System.debug('opPayment_Terms__c ----'+op.Payment_Terms__c );
System.debug('opId----'+op.Id);
oppList = [SELECT Name,Payment_Terms__c,Account.BillingCountry,(SELECT Margin__c FROM OpportunityLineItems) FROM Opportunity WHERE Id =: op.Id];
System.debug('oppList ----------'+oppList );
System.debug('oppListPayment_Terms__c ----------'+oppList[0].Payment_Terms__c );
}
Test class code :
static testMethod void OpportunityController2() {
Account acc = new Account(Name='Testing1',BillingCountry='USA');
insert acc;
System.debug('::::::acc::::::::::'+acc);
Opportunity opp = new Opportunity(Name='Test Opp4',AccountId=acc.Id,
Payment_Terms__c = 'testing 60',CloseDate=System.today().addMonths(1),StageName='Negotiations');
insert opp;
System.debug('::::::opp::::::::::'+opp);
System.debug('::::::opp.Payment_Terms__c:::::::::::'+opp.Payment_Terms__c);
OpportunityController controller1 = new OpportunityController(new ApexPages.StandardController(opp));
}
In that Test code I have inserted one Opportunity with Payment_Terms__c field value.I am running the test method I got the following output:
:::::::acc::::::::::Account:{Name=Testing1, BillingCountry=South Africa, Id=001S000000cqIbiIAE}:
:::::opp:::::::::::Opportunity:{Name=Test Opp4, StageName=Negotiations, Payment_Terms__c=testing 60 days, AccountId=001S000000cqIbiIAE, Id=006S0000006dj9hIAA, CloseDate=2013-04-15 00:00:00}
::::::opp.Payment_Terms__c:::::::::::testing 60 days
Original class output:
oppList ----------(Opportunity:{Name=Test Opp4, AccountId=001S000000cqIbiIAE, Total_List_Price__c=0.00, Is_Step2_Required__c=false, Id=006S0000006dj9hIAA, Total_Discount__c=0.00})
opportunity.Payment_Terms__c ----------null
In original class code Payment_Terms__c field always shows null value.But I have inserted Payment_Terms__c value in Test class.I noticed in debug log i.e Payment_Terms__c field values didn't add in the oppList.Is any one help to get the Payment_Terms__c value in Original class?
Can you check on this oppportunity record '006S0000006dj9hIAA' whether field 'Payment_Terms__c' is populated or not.
I am sure that this is not populated and hence you are not getting it.
Hi
I tried the same code, but the value is displayed correctly in the Debug log.
Below is the debug log: