0

I'm refactoring a recursive function to avoid hitting governor limits on SOQL queries.

In order to keep SOQL queries out of a for loop, I'm using dot notation to retrieve a lookup relation (Residence) that exists on the parent account (household) of the object (wish) being queried.

I had no problem when I had a distinct query on the Household object inside a for loop. But for some reason, I can't use the Residence as the parameter on the recursive call.

Here's my call

    // GET THE FOLLOWING DATA FOR EACH WISH AGAINST THE TARGET PROPERTY
    // Wish Name
    // Name and Id of parent Household (ie Owner of this wish)
    // Name and Id of parent Household's Residence (may be null)

    List<Wish__c> wishes = new List<Wish__c>([ SELECT Name, 
                                              Household__c, 
                                              Household__r.name,
                                              Household__r.Residence__c,
                                              Household__r.Residence__r.id,
                                              Household__r.Residence__r.name, 
                                              Property__c, 
                                              Property__r.name 
                                              FROM Wish__c 
                                              WHERE Property__c = :targetProperty.Id]);

Which works just fine to get me the id I want

Query tested in SoqlX

But when I try to use either Household__r.Residence__c or Household__r.Residence__r.id in the call to the recursive function, I get the following error

Method does not exist or incorrect signature: void findDaisyChains(Integer, Id, DaisyChainFinder.daisyChain, Integer) from the type DaisyChainFinder

The call looks like this

findDaisyChains(step+1, thisWish.Household__r.Residence__c, daisyChainToUse, maxSteps); // increment the step and execute recursive call

The function is declared as follows

private static void findDaisyChains(Integer step, Property__c targetProperty, daisyChain thisDaisyChain, Integer maxSteps)

It's expecting a property, but won't accept either way of passing it the id of a property.

Any suggestions?

2
  • 1
    Your code doesn't match at all. The line where you share your call has a method named findDaisyChains with four parameters. Your method where you share the declaration has a method named getDaisyChainsFromProperty with two parameters. Can you edit your post to include all relevant method declarations? The state of completeness here makes it difficult to assist you.
    – Adrian Larson
    Jan 22, 2019 at 21:09
  • Woops. Bad copy paste. Fixed.
    – Justin
    Jan 22, 2019 at 21:12

1 Answer 1

1

LookupField__c is an Id. As long as it looks up to a single object of the correct type, you can use the LookupField__r object, instead:

findDaisyChains(step+1, thisWish.Household__r.Residence__r, daisyChainToUse, maxSteps); 
// increment the step and execute recursive call
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .