When you observe the Fetch XML generated by joining Accounts and Contacts table, the from and to attributes of the<link-entity> contain the ‘parentcustomerid’ and ‘accountid’, which are GUIDs.

These GUIDs define the relationship (i.e., primary and foreign keys).

Executing the above Fetch XML query returns all the Account records related to the Contact records.

Did you know that it’s possible to specify the ‘from’ and ‘to’ attributes using columns that aren’t part of a defined relationship?

For example, following Fetch XML query finds pairs of records where the Name column of an account record matches the FullName column of a contact record regardless of whether they reference each other in any of the lookup columns.

<fetch>
   <entity name='account'>
     <attribute name='name' />
     <link-entity name='contact'
       from='fullname'
       to='name'
       link-type='inner'
       alias='contact'>
       <attribute name='fullname' />
     </link-entity>
   </entity>
 </fetch>

To test the above query, let’s create Account and Contact records with the name Contoso Ltd and test the Fetch XML. Ensure that the Contoso Ltd Account and Contact records are not related.

As shown below, the Fetch XML query returns a single matching Account record with the name Contoso Ltd.

Key Points to consider:

  • Columns specified in the from and to attributes must be of the same type
  • The following column types can’t be used in from and to attributes:

Refer this docs link for more details.

🙂

Advertisements
Advertisements

Leave a comment