Skip to main content
Glenn Daly (Pod Point) 님이 #Data Management에 질문했습니다
I'm trying to reference the product2 name from an opportunity record. However it's giving me this error and not allowing me to save the code.

 

"Invalid foreign key relationship: Opportunity.opportunitylineitem"

 

How should I be referencing this field?

 

global class OpOwnerOldService_Scheduled Implements Schedulable

 

    {

 

        global void execute(SchedulableContext sc)

 

        {

 

            sendEmailtoOppOwner();

 

        }

 

        public void sendEmailtoOppOwner()

 

        {

 

            List<Opportunity> listOpportunity = new List<Opportunity>();

 

            listOpportunity = [SELECT Id, OwnerId FROM Opportunity WHERE Id In (SELECT OpportunityId FROM OpportunityLineItem WHERE Product2.Make_unavailable_for_opps_and_proposals__c = TRUE)];

 

            for(Opportunity opp : listOpportunity)

 

            {

 

               Messaging.SingleEmailMessage mail = new Messaging.SingleEmailMessage();

 

mail.setTargetObjectId(opp.OwnerId);

 

mail.setReplyTo('glenn.daly@live.com');

 

mail.setSenderDisplayName('Salesforce Support');

 

mail.setSubject('Historic Service attached to current opportunity : ');

 

mail.setPlainTextBody(opportunity.Id +' has been created.');

 

mail.setSaveAsActivity(false);

 

                

 

Messaging.sendEmail(new Messaging.SingleEmailMessage[] { mail });

 

            }

 

            update listOpportunity;

 

        }

 

    }
답변 1개
0/9000