function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Sarthak Bajaj 6Sarthak Bajaj 6 

SOQL for opportunitylineitem

I want to get Employer_Meeting_Date__c field from opportunitylineitem but the condition is that i want only those recoeds for which task is created therefore related to field(whatid) need to be used.

the query which i currently used is 
SELECT Employer_Meeting_Date__c,Id,OpportunityId FROM OpportunityLineItem WHERE OpportunityId IN (select id from opportunity where id IN (select whatid from task))


but it is giving an error
MALFORMED_QUERY: 
where id IN (select whatid from task))
^
ERROR at Row:1:Column:158
Nesting of semi join sub-selects is not supported
Nayana KNayana K
This may work :
SELECT Employer_Meeting_Date__c,Id,OpportunityId FROM OpportunityLineItem WHERE OpportunityId IN ( select whatid from task)
Sarthak Bajaj 6Sarthak Bajaj 6
Thanks for the help Nayana K.

I tried your query, but this query is also giving an error which states:
ERROR at Row:1:Column:119
Entity 'task' is not supported for semi join inner selects

The approach which i then selected is creating a new SET
set<id> whatid = new set<id>();
for(Task t :trigger.new){
   whatid.add(t.Whatid);
  }

This fetches only the oppoortunityid from task which are required.Then
List<OpportunityLineItem> OLTQueryList= [SELECT Employer_Meeting_Date__c,Id,Id,OpportunityId FROM OpportunityLineItem WHERE OpportunityId IN : whatid];

This solved my purpose.Still i didn't came to know why cant i directly query task object using joins.