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
clouddev@surashriclouddev@surashri 

SOQL Query

Hi,

 

I am running below query

 

SELECT account.name, account.partner_sales_person__c, account.crm_product__r.name, name, (select whoid, whatid from tasks where subject = 'DEMO') FROM contact WHERE account.partner_sales_person__c in ('clouddev')  AND account.crm_product__c != null and name like '%gore'

  and getting 2 records as shown.

 

Tasks	Name	Account

Tasks	Stephen Gore	Account
-----                   --------
	Steve Gore	Account
                        --------

 

Current relation is

 

Account 'XXX' has 2 contacts (Stephen Gore, Steve Gore) and only 'Stephen Gore' has Task DEMO created so I don't need 'Steve Gore' record as it has no task attached to it.

 

Please reply,

 

Thanks,

 

Clouddev

 

 

 

 

Jaffer Ali.Jaffer Ali.

Instead of querying on account.You can query on task , extract all field of account by using field reference "account" and place all required fields with where clause .Then as a result you will find all tasks with account information.Afterwards you can place some logic in Apex Code and extract accounts from tasks soql list.

gbu.varungbu.varun

Hi you should filter Contact ID on the basis of Task also. For Example:

SELECT account.name, account.partner_sales_person__c, account.crm_product__r.name, name, (select whoid, whatid from tasks where subject = 'DEMO') FROM contact WHERE account.partner_sales_person__c in ('clouddev')  AND account.crm_product__c != null and name like '%gore' and ID IN (select whoid from tasks where subject = 'DEMO')