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
EnryEnry 

Navigate relationships

Hi,

My objects are:

 

CONTACT(lookup)-------------ACCOUNT (master)-------ACCOUNT PLAN(detail/master)--------INFLUENCER(detail)

 

I want create a lookup on INFLUENCER that shows only the contacts related.

With soql from the object INFLUECER how can i get the account and after the contact related?

 

I have written this:

 

 

Select Account.id,id,name from contact where Account.id IN (SELECT Account_Plan__r.Account__r.id FROM Influencer__c)

 

 

but i get an error :

The inner select field 'Account_Plan__r.Account__r.id' cannot have more than one level of relationships

 Any advice?

 

Thank you in Advatage.

BR.

sourav046sourav046

If i got it correctly ,you want only those Contacts and Account IDs whose related Accounts have atleast 1 Influencer record .

That means if an Account has got no Influencer child record ,you dont wanna retrieve the Contacts for that Account .

 

Is it what you want ?

EnryEnry

This is my solution:

 

 

Set<Id>ids=new set <Id>();

 

 

for(Influencer__c lacc :[SELECT Account_Plan__r.Account__r.id FROM Influencer__c]){

  ids.add(lacc.Account_Plan__r.Account__r.id);

}

 

Contact[]lc=[SELECT Account.id from Contact where Account.id IN :ids];

 

Thank you!

BR