The Custom Query functionality relies on the use of Apex programming language, so it is a bit technical. If this is your first exposure to Apex, don't worry. This feature is optional to use, and Maven Documents can work perfectly fine without it.
Custom Query enables you to define your custom Apex class which can enrich your current Salesforce data with, basically, anything. Having this tool at your disposal means that you are not dependent on only the data you can get with Query Builder but also on your fully custom logic. The decision to use it would most likely occur in the following scenario:
You can find your Custom Query details in the related list on Document Solution Object.
If you click on the New button, you can input your Custom Query Name and Apex Class Name.
The Apex Class you plan to use has to implement the CustomQueryInterface global interface, packaged in the Maven Documents app:
global interface CustomQueryInterface {
Object executeCustomQuery(Map<String, Object> GraphQLData, String requestId);
}
When you've implemented it, with the executeCustomQuery method, you can return some of the following:
Furthermore, at your disposal, you also have Map<String, Object> GraphQL Data map, and String requestId.
Feel free to use those bits of information in any shape, way, or form when returning the resulting value.
Here are a couple of examples of the Apex classes that are implementing mmdoc.CustomQueryInterface:
A:
Custom Query Name: MyCustomQueryName
Apex Class Name: MyCustomApexClass
global class MyCustomApexClass implements mmdoc.CustomQueryInterface {
public Object executeCustomQuery(Map<String, Object> GraphQLData, String requestId) {
return 'This is my custom value!';
}
}
B:
Custom Query Name: MyCustomQueryName2
Apex Class Name: MyCustomApexClass2
global class MyCustomApexClass2 implements mmdoc.CustomQueryInterface {
public Object executeCustomQuery(Map<String, Object> GraphQLData, String requestId) {
Map<String, String> myMap = new Map<String, String>();
myMap.put('myKey', 'This is my custom value inside a Map' );
return myMap;
}
}
C:
Custom Query Name: MyCustomQueryName3
Apex Class Name: MyCustomApexClass3
global class MyCustomApexClass3 implements mmdoc.CustomQueryInterface {
public Object executeCustomQuery(Map<String, Object> GraphQLData, String requestId) {
Map<String, String> myMap = new Map<String, String>();
myMap.put('myKey', 'This is my custom value inside a Map' );
List<Map<String, String>> myList = new List<Map<String, String>>();
myList.add(myMap);
return myList;
}
}
With that logic in place, you are ready to reference Custom Query Name inside your Google Doc, Google Sheet, DOCX, or XLSX template!
Here is the side-by-side of the Google Docs template and the generated file, using the example from above: