Why a custom query?
A custom query allows me to obtain a 2nd starting point different from the main object to allow me to search for data in another object that does not have a direct link with my main object.
Example
You are on a main object at the level of a contact, you may need to display the list of current opportunities on the account of the contact in question.
The object model would look like this:
Create a secondary object with only one result
#1
Here we want to retrieve only one result, which is an account.
Go to the “Gonexa Assistant” component
Click on “Custom Request”
Choose the Salesforce object in question [In our case it's “Account"]
The label is supplied by default, but you can change it for greater clarity in the model.
Write the request to retrieve the ID, this SOQL query allows you to retrieve the record you want.
Recovery request in our example : SELECT AccountId FROM Contact WHERE id = {RecordId}
SELECT accountId
AccountID is the API name of the specific field on the Contact Object. Attention, if you are on a custom lookup, the field could have been called “Account__c”
FROM Contact
We simply indicate the main object here from which we make the request
WHERE id = {recordID}
This makes it possible to identify the account that is linked to the contact. The {recordID} tag should be formalized precisely in this way.
Create the child object of the secondary object “Opportunity”
After creating a secondary object using a custom query, you can now create child objects in exactly the same way as using a primary object.
From the Gonexa Assistant component, the Account secondary object appears in red in the same way as a main object
Other ID fetch request examples
Main object is Quote and I want to do a Secondary Account
Retrieval request : SELECT accountID FROM Quote WHERE id = {recordID}
Main object is Session and I want to do a Secondary Object Account
Retrieval request : SELECT account__C FROM Session_Formation__c WHERE id = {recordID}
Main object is Opportunity and I want to do a Secondary object Account Partner Account
In this case, a nested SOQL query is created.
Retrieval request : SELECT partner_account__C FROM Account WHERE Id IN (SELECT accountID FROM Opportunity WHERE Id = {recordID})
💡 Support tip, take Salesforce Inspector to find the query that returns the correct record that corresponds to the Main object.
Create a secondary object with multiple results
#2
In the case of a custom query with multiple results, the chosen object may or may not be linked to the main object, and must be in a table in the document.
Go to the Gonexa Wizard component, and click on “Custom Query”
Choose the Salesforce object concerned, the label is supplied by default but you can modify it for greater clarity in the model
Select “All records”, a few fields appear in addition
If the object you want to use is linked to the main object of the document template, fill in the link field between the two in the “Link to the main object” field
If there is no link you can leave this field empty
You can then add a filter and a sorting on the records to be retrieved if necessary.
Example 1: Secondary object with a link to the main object
The main object is Account, we want to show campaign members corresponding to account contacts.
Example 2: Secondary object not linked to the main object
We want to show all the Options products available in our Salesforce and add them to our document
In this case, we choose the object “Product”
It is possible to rename the object label to “Options” for greater clarity in the document
We select “All recordings”
Since we want all the products available in our Salesforce, it is not necessary to fill in the “Link to the main object” field, leave it empty
Once this is done, we can add our tags to our document. We are retrieving several products, so the tags must be in a table, in the same way as a child object