I am creating a service record when opportunity is closed won and product code in opportunity line item is null. I am filling the new service record with the values from opportunity line item and opportunity, now they want data from account object, please help me to figure out this When i uncomment the Account Acc....i get invalid foreign key relationship:opportunitylineitem.op
for (OpportunityLineItem oli:[SELECT OpportunityId,Product2.name
FROM OpportunityLineItem
where ProductCode = null
AND Opportunityid IN :opps]){
Opportunity op = Trigger.newMap.get(oli.OpportunityId);
// Account Acc = Trigger.newMap.get(oli.op.AccountId);
lServ.add(new Services__c(
Account__c = op.accountid,
Policy_Number__c=op.Policy_Number__c,
Opportunity__c=oli.OpportunityId,
Vendor__c =op.Issuing_Carrier__c,
// Source__c=Acc.Source__c,
Start_Date__c=op.Effective_Date__c,
End_Date__c= op.Expiration_Date__c,
Product_Name__c=oli.Product2.name));
}
if (lServ.size() > 0){
insert lServ;
}
Opportunity
andAccount
from sameMap
. BTW, the relation shouldopl.Opportunity.Account
if you have retrieved it in your SOQL queryOpportunity
object just getAccount
details from that.i.e.Source__c=op.Account.Source__c
and same for any otherAccount
fields