I'm trying to insert a new record into an object where I pull information from OpportunityLineItem
, Product
, Opportunity
, and Account
. I did a query and get the results I want. Then I go to create a new record with the results of the query and I get the error:
Variable does not exist:
oli.Opportunity.AccountId
oli
is the name I used in the for loop to search for OpportunityLineItem
records, what am I doing wrong? In other variable does not exist posts it references when you create a variable and then in a different method try and reference that variable again. This is all in the same method so I am confused.
Example:
public with sharing class RevenuePipelineHandler {
public static void createRevPipeline(Set<Id> oppyIds) {
List<Revenue_Pipeline__c> revPipeline = new List<Revenue_Pipeline__c>();
for(OpportunityLineItem oli:[SELECT Start_Date__c,
End_Date__c,
TotalPrice,
Is_Fund__c,
OpportunityId,
Opportunity.AccountId,
Opportunity.Account.Account_BU_2__c,
Opportunity.CurrencyIsoCode,
Opportunity.Practice__c,
Opportunity.Cash_or_Barter__c,
Opportunity.StageName,
Opportunity.Sales_Order_Approved_Date__c,
Product2Id,
Product2.ALR_Retailer__c,
Product2.Product_LOB__c,
Product2.Product_Type__c,
Product2.Family,
Product2.Product_Group__c,
Product2.Product_Offering__c
FROM OpportunityLineItem WHERE OpportunityId IN :oppyIds])
{
revPipeline.add(new Revenue_Pipeline__c(
Account__c = oli.Opportunity.AccountId,
ALR_Retailer__c = oli.Product2.ALR_Retailer__c,
Cash_Barter__c = oli.Opportunity.Cash_or_Barter__c,
Cross_Practice__c = oli.Opportunity.Account.Account_BU_2__c,
CurrencyIsoCode = oli.Opportunity.CurrencyIsoCode,
External_Id__c = oli.Product2.Family + '/' + oli.Product2.Product_Group__c + '/' + oli.Product2.Product_Offering__c,
Is_Fund__c = oli.Is_Fund__c,
Name = oli.OpportunityId + '-' + oli.Product2Id,
Opportunity__c = oli.OpportunityId,
Practice__c = oli.Opportunity.Practice__c,
Product_AU__c = oli.Product2.Product_LOB__c,
Product_End_Date__c = oli.End_Date__c,
Product_Price__c = oli.TotalPrice,
Product_Start_Date__c = oli.Start_Date__c,
Product__c = oli.Product2Id,
Revenue_Type__c = 'DANDAN',
Subscription_Type__c = oli.Product2.Product_Type__c));
}
insert revPipeline;
}
}