Drawloop - Obtaining Data Through a Junction Object Using SOQL (Contact Roles)

  • 15 February 2022
  • 2 replies
  • 777 views

Userlevel 5
Badge +19

Topic

How to use a SOQL relationship to obtain data through a Salesforce Junction Object. This is also known as replication through a lookup.

 

Instructions

1. Create a new SOQL relationship on your DocGen Package
2. Give the relationship an alias. Be sure it is unique and that it does not match the naming convention of any existing objects or fields in your Salesforce Org.
4. Paste the SOQL Query into the box
5. The example below will pull in all Opportunity Contact Roles:

Primary Object: Opportunity (Opportunity)

Related List Junction Object: Contact Roles (OpportunityContactRole)

Object In Junction Object: Contacts (Contact)


SELECT Contact.name FROM OpportunityContactRole WHERE Opportunity.Id = '<<Opportunity_ID>>'



SELECT lookup_(Object in Junction)api_name.field
FROM junction_object_api_name
WHERE main_object_api_name.id = '<<main_object_record_id_tag>>'


For custom objects, be sure to append __r at the end for dot notated fields.

SELECT lookup_(Object in Junction)api_name__r.field FROM junction_object_api_name WHERE main_object_api_name__r.id = '<<main_object_record_id_tag>>'

 

Related Links

 


2 replies

Once you have the list, how can you map to documents?  I would like to be able to map different fields from each of those records to a PDF.

I think I found a small error in this post. I was having difficulty getting this to work, but then I tried creating the query with the WHERE statement just being the field that references the main object instead of "main_object_api_name__r.id".  That made it work for me.

Reply