0

I'm trying to get a table of all the individual tasks that belong to specific leads. I only want to pull tasks that belong to leads with a custom checkbox field "hedgehog_account__c = true." The hedgehog_account__c field is on the lead record.

Here's the SOQL query attempting to do this.

SELECT Completed_Date__c, CreatedDate, Subject, Subject__c, CreatedBy.Name, Owner.Name 
FROM Task 
WHERE Completed_Date__c = LAST_N_DAYS:90 AND Lead.Hedgehog_Account__c = true

I also tried nesting ...(SELECT Lead.hedgehog_account__c FROM Lead WHERE hedgehog_account__c = true)... in the main SELECT statement of my SOQL query, but that also didn't work.

I got an error in either case saying :

Lead relationship not understood, please use __r to specify any custom relationship fields.

I'm very new to SOQL (limited experience with SQL as well), so apologies for any glaring errors. Any suggestions on the best place to learn APEX and SOQL would be greatly appreciated as well!

2
  • You can learn a bunch about Salesforce in general over at the Salesforce Trailhead; just sign in with your favorite social media account, it'll give you a developer edition org to play with, and you can learn all about many aspects of salesforce. The Developer Trails in particular should cover queries, Apex Code, triggers, asynchronous calls, callouts, web service calls, and more.
    – sfdcfox
    Nov 28 '16 at 16:16
  • Thanks for the advice. I've done the Administrator Trails, but will have to try out the Developer Trails next. I appreciate it! Nov 28 '16 at 18:40
1

You should be able to use a criteria sub-query to get your information:

SELECT ... FROM Task 
WHERE Completed_Date__c = LAST_N_DAYS:90 AND 
      WhoId IN (SELECT Id FROM Lead WHERE Hedgehog_Account__c = TRUE)
1
  • Thanks! That did the trick. I really appreciate the help! Nov 28 '16 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.