Skip to main content 3월 5~6일에 샌프란시스코의 TDX 또는 Salesforce+에서 열리는 AI 에이전트 시대를 위한 개발자 컨퍼런스에 참여하세요. 지금 등록하기.
Jon Pilarski (USD) 님이 #Apex에 질문했습니다
Hello. I have 3 custom objects, WorkRequest, Project and ProjectRequirements. ProjectRequirements is child to Project and Project can be associated to a WorkRequest. In single query I can query data easily as such:

 requirementList = [SELECT  id, 

                            ResourceAssigned__c,

                            Project__r.Work_Request__r.Work_Request_Status__c, 

                            Status__c ,  

                            Project__r.Name, 

                            Project__r.Project_Status__c, 

                            Project__r.Work_Request__r.Name,

                            Project__r.Work_Request__r.Short_Description__c,  

                            Project__r.Work_Request__r.Problem_Description__c,

                            Comments__c,

                            Name,

                            AddRequirementDetails__c

                      FROM USD_ProjectRequirements__c

                     WHERE Project__r.Work_Request__r.Name  != null

                       AND (ResourceAssigned__c IN :idList];    

However, what I also want to do is query in single query WorkRequests assigned to a rresource which have not been related to a Project. Anywat to do this in APEX?  Basically, the equivalent of SQL UNION operator.

Thanks in advance,

Jon
답변 3개
  1. 2015년 6월 29일 오전 8:27
    You can try something like:

    Select Id, (Select Id From Projects__r) From Work_Request__c

    This way you have:

    • All the WR objects (assigned to you, if the assignation is done with sharing rules  or add a OwnerId filter at the end or other filter is appropriate for filtering)
    • If a WR object is not assigned to anything, you will find an empty "WR.Projects__r"  list(assuming Projects__r is the inverse relationship name for the "Work_Request__r" relation on Project__c)
    • Otherwise you'll also have all the the Proejcts related to the WR objects.

    Does it make sense?

     
로딩 중
0/9000