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
mariappangomathirajmariappangomathiraj 

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?

Vinit_KumarVinit_Kumar

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.

Darshan FarswanDarshan Farswan

Hi 

 

I tried the same code, but the value is displayed correctly in the Debug log.

Below is the debug log:

 

04:40:29.183 (1183438000)|USER_DEBUG|[11]|DEBUG|oppList ----------(Opportunity:{Name=Test Opp4, Payment_Terms__c=testing 60, AccountId=0019000000MnLdhAAF, Id=00690000009oS6JAAU})
04:40:29.183 (1183449000)|SYSTEM_METHOD_EXIT|[11]|System.debug(ANY)
04:40:29.183 (1183462000)|METHOD_ENTRY|[12]|01p90000002erlA|OpportunityController.__sfdc_oppList()
04:40:29.183 (1183484000)|METHOD_EXIT|[12]|01p90000002erlA|OpportunityController.__sfdc_oppList()
04:40:29.183 (1183527000)|SYSTEM_METHOD_ENTRY|[12]|System.debug(ANY)
04:40:29.183 (1183535000)|USER_DEBUG|[12]|DEBUG|oppListPayment_Terms__c ----------testing 60
04:40:29.183 (1183540000)|SYSTEM_METHOD_EXIT|[12]|System.debug(ANY)