0

Trying to get a sub-query within the Account trigger. Account has a lookup to itseff self in field entity__c How do i get the entity__c records related to the parent account i tried the above soql but no luck i tried in query editor and it says no such e

Account has a self lookup field: entity__c. I am checking for a condition: date__c > today in entity__c is found

How do I get the fields from the entity__c related to it's parent Account record? I have tried SOQL(below) but didn't seem to work.

Select id,(SELECT Id,Name,date__c From Account where RecordtypeId= '0121N003401DbNk'),entity__r From Account 
5
  • This is a similar problem to salesforce.stackexchange.com/questions/291009/… and I think my answer on that question would help you with yours. Also "it doesn't work" is usually not sufficient for a description of the issue. If you're getting an error message, it's always a good idea to include the full text of the error (don't paraphrase it).
    – Derek F
    Jan 14 '20 at 20:31
  • Account has a lookup to itseff self in field entity__c How do i get the entity__c records related to the parent account i tried the above soql but no luck Jan 14 '20 at 21:07
  • To Derek's point, his answer has all you need. Use the anonymous apex to figure out the child relationship name on the self-lookup and go from there. Jan 14 '20 at 21:12
  • I tried this select id, Entity__r.Id from Account where RecordtypeId= '0121N000001jsNk' AND Entity__r.Date__c > System.TODAY() AND condition is throwing error as error parsing query how do we write this Jan 14 '20 at 21:25
  • 1
    Entity__r.Date__c > :System.TODAY() - you need a bind variable notation if using apex; if straight SOQL you need to use a date literal (see doc)
    – cropredy
    Jan 15 '20 at 1:44

Your Answer

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

Browse other questions tagged or ask your own question.