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
notsosmartnotsosmart 

Test Method Wrapper Class Field Population

I am trying to populate a wrapper class field in my test method.  I attempted the syntax used in the functional controller extension which populates the key field.  Only I'm hard coding an associated field. The object is a custom junction object for the 1 to many relationship.

 

My error is:  Variable does not exist: Opportunity__c at line 64 column 6

--------------

The class is:

 

public class OpportunityLineItem {

public Integer lineNumber{ get; set; }
public Boolean isDeleted{ get; set; }
public tripOpportunityAssociation__c opportunity { get; set;}

public opportunityLineItem(){
opportunity = new tripOpportunityAssociation__c();
lineNumber = 0;
isDeleted = false;
}

public OpportunityLineItem(Integer pLineNumber, tripOpportunityAssociation__c pOpportunityItem){
opportunity = pOpportunityItem;
lineNumber = pLineNumber;
isDeleted = false;
}

 

The Controller extension population of the key field is:

 

 PageReference addAttendee;

 

// Populate new opportunity items with report id.

for ( TripOpportunityAssociation__c item : opportunityItemsToUpsert ){
if (item.Trip_Opportunity__c == null){
item.Trip_Opportunity__c = tripReport.id;

}
}

 

---------------

 

The test method syntax is:

@isTest private class TestTripRptExt3 {
public TestTripRptExt3() {

}
//Public attributes.
public ApexPages.StandardController controller;

public Boolean CancelConfirm = false;
//Private attributes.
private Trip_Report__c tripReport;
private String reportItemsMessage;

private Integer attendeeLineCount = 0;
private Integer opportunityLineCount = 0;

//Controller extension constructor.
public TestTripRptExt3(ApexPages.StandardController stdController) {


static testMethod void testTripRptExt3() {

 

// controller.setUnique_Name & basic fields(
controller.tripReport.Unique_Name__c = 'Test Method Name';
controller.tripReport.Date_of_Meeting__c = date.parse('07/13/2012');
controller.tripReport.Meeting_Notes__c = 'Test Method Note';

 

 

 

PageReference addOpportunity;
for(OpportunityLineItem item : controller.opportunityLineItemList) {
item.Opportunity__c = 'Great Opportunity';
}

}

Any ideas on this?  Thanks


Damien_Damien_

It would be useful if you showed us what line 64 was.

notsosmartnotsosmart
The code section is below: The particular line is item.Opportunity__c = 'Great Opportunity'; and the error is: Error: Compile Error: Variable does not exist: Opportunity__c at line 59 column 6 PageReference addOpportunity; for(OpportunityLineItem item : controller.opportunityLineItemList) { item.Opportunity__c = 'Great Opportunity'; } Thanks
Damien_Damien_

Ahhh yes, The Opportunity__c field is a lookup.  That means it requires an Id to be assigned to it.  Not a String.

notsosmartnotsosmart
Thanks, I made it populated with an id lookup but still the same error. When I comment out just the line that populates it, I got: Error: Compile Error: Variable is not visible: opportunityLineItemList at line 59 column 38 This was the for loop. It's a clue that I've overlooked something ahead. But what. Any other ideas. Thanks again.