You need to sign in to do that
Don't have an account?
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
It would be useful if you showed us what line 64 was.
Ahhh yes, The Opportunity__c field is a lookup. That means it requires an Id to be assigned to it. Not a String.