SOQL 帮助:如何在 apex SOQL 中获取正确的 contactID,我想在任务创建中将 Contact ID 分配到字段 whoid

SOQL help: How to get the correct contactID in apex SOQL, I want assign Contact ID into field whoid in the Task creation

这个 SOQL 给我 Account.Maintenance_Contact__r.id(003C000002M6kiDIAR)

Select ID, owner.id, owner.isactive, 
                                 Master_Opportunity__c, Internal_Start_cycle_days_ROPP__c,Invoice_cycle_days_ROPP__c,
                                        **Account.Maintenance_Contact__r.id** 
                                 from Opportunity 
                                 where Master_Opportunity__c = null 
                                 and Account_Record_Type__c != 'Personal Use Accounts'
                                 and Renewal_Stage__c in ('Pending PO','Pending SLSA','Pending OEM')      
                                 and Invoice_cycle_days_ROPP__c = NEXT_MONTH ]

但是当我添加到 Apex 时它给我这个 Account.Maintenance_Contact__r.id 是“001C0000013yu9QIAQ”而不是联系人 ID。

public class Oppjob_Task_PORequired_cls {
    public void createTaskforOpp() {
          List<Opportunity> oppList = [Select ID, owner.id, owner.isactive, 
                                 Master_Opportunity__c, Internal_Start_cycle_days_ROPP__c,Invoice_cycle_days_ROPP__c,
                                        Account.Maintenance_Contact__r.id 
                                 from Opportunity 
                                 where Master_Opportunity__c = null 
                                 and Account_Record_Type__c != 'Personal Use Accounts'
                                 and Renewal_Stage__c in ('Pending PO','Pending SLSA','Pending OEM')      
                                 and Invoice_cycle_days_ROPP__c = NEXT_MONTH 
                                 and id ='006C000001CSbQIIA1'];
    List<Task> taskList = new List<Task>();
        system.debug('oppList' + opplist);

     For(Opportunity opp : oppList) {
      if(opp.Owner.isActive == true) {
                   Task newTask = new Task(
                         WhatId = opp.Id,
                        OwnerId = opp.OwnerId,
                        Team__c = 'PreSales Support',
                    // Task_Type__c = 'RMT Follow Up',
                          WhoID = opp.Account.Maintenance_Contact__r.id,
                        //WhoID = '003C000002M6kiDIAR',
                   ActivityDate = system.today().adddays(3) ,
                        Subject = 'PO Required Follow-up',
                    Description = 'Follow up for customer PO');
         taskList.add(newTask);
         }
        }
     system.debug('TaskList:' + tasklist.size());
    if (tasklist.size()>0){
        insert taskList;
    }

    }
}

我得到了问题的答案。

**List<Opportunity> oppList = [Select ID, owner.id, owner.isactive, 
                                 Master_Opportunity__c, Account.id, Internal_Start_cycle_days_ROPP__c, Invoice_cycle_days_ROPP__c
                                       ,**Account.Maintenance_Contact__c**
                                 from Opportunity 
                                 where Master_Opportunity__c = null 
                                 and Account_Record_Type__c != 'Personal Use Accounts'
                                 and Renewal_Stage__c in ('Pending PO','Pending SLSA','Pending OEM')      
                                 and Invoice_cycle_days_ROPP__c = NEXT_MONTH 
                                 and id ='006C000001CC3AYIA1'];

    List<Task> taskList = new List<Task>();
     For(Opportunity opp : oppList) {
      if(opp.Owner.isActive == true) {
                   Task newTask = new Task(
                        WhatId = opp.Id,
                        OwnerId = opp.OwnerId,
                        Team__c = 'Renewal Management',
                   Task_Type__c = 'RMT Follow Up',
                          WhoID = **opp.Account.Maintenance_Contact__c,**
                   ActivityDate = system.today().adddays(5) ,
                        Subject = 'PO Required Follow-up',
                    Description = 'Follow up for customer PO');
         taskList.add(newTask);
         }
        }**