SOQL relationship queries in custom module

Created on 14 February 2022, almost 3 years ago
Updated 31 January 2024, 11 months ago

Problem/Motivation

Hi, I have set up the Salesforce module and created a custom module to perform a custom query. One of the fields I need to select is a lookup field and I cannot get the value of the related field when I query the related parent object and try and select any child fields.

Name field appears in the parent and is linked via the lookup relationship in the child field.

    $query = new SelectQuery('Parent__c');
    $query->fields = [
      'Child__r.Id',
      'Parent__r.Name',
      'Child__r.Resort__c',
      'Child__r.Airport__c',
      'Child__r.Taxis__c',
    ];
    $query->addCondition("Parent__r.Name", "'Bini Segui'", '=');
    $sfResponse = \Drupal::service('salesforce.client')->query($query);

A similar query is returning results when looking at one object at a time so I know the fields and objects have the correct name etc. but for parent and child queries the child values are blank.

In a normal SOQL query you can reference parents and children via dot notation or via a subquery using their relationship name (ending __r) is this possible in the drupal query method? If so how do I do it?

Many thanks

Rich

πŸ’¬ Support request
Status

Closed: outdated

Version

4.0

Component

salesforce_pull.module

Created by

πŸ‡¬πŸ‡§United Kingdom Richard Moger

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • πŸ‡ΊπŸ‡ΈUnited States rishi kulshreshtha

    @AaronBauman, as per the instructions in this comment on the Retrieve attachment content β†’ , I have added a subquery as a field under pullQueryAlter. The other fields added under this function are working fine and I can see their values while debugging and they work when added under pullPreSave. However, I am unable to see the subquery field or its value under pullPreSave. What steps should I take in order to retrieve the value of the relationship that was added under pullQueryAlter from Salesforce to Drupal?

    An example of the added subquery is:

    case 'my_mapping':
      // Adds a field.
      $query->fields['Drupal_ID__c'] = 'Drupal_ID__c';
      // Adds a subquery.
      $query->fields[] = 'SELECT Contact__r.Name, Contact__r.Email, Contact__r.Alternate_e_mail__c, Role__c FROM Project_Roles__r';
      break;
    
  • Status changed to Closed: outdated 11 months ago
  • πŸ‡ΊπŸ‡ΈUnited States AaronBauman Philadelphia

    I'm doing some cleanup on unsupported branches.
    Please re-open this issue and update the version to 5.0.x-dev if this issue is still applicable to the latest release.

Production build 0.71.5 2024