A QVar (query variable) runs a configured query when a document is generated and stores the result so another parameter can reuse it. Instead of hardcoding a value, such as a Contact ID for an email recipient or a template ID, you let a query find the value based on the record the document is generated from.

Use a QVar when a value that another parameter needs isn't fixed but depends on data elsewhere in Salesforce. For example:

  • Find the right contact to email based on the opportunity's primary contact role.
  • Select one or more templates based on opportunity stage, account type, industry or product.
  • Pull any other record-specific value that another parameter needs.

QVar parameters

ParameterPurpose
QVar0IdThe ID of the query that QVar 0 runs. Its result becomes available for reuse.
QVar0FormatOptional. Controls how the query result is formatted before it's passed on, for example when the query returns multiple values.
{QVar0}A reference to the result of QVar 0. Use it inside another parameter to insert the result as that parameter's value.

The number (0 in these examples) identifies a specific QVar. To use more than one query variable, continue the pattern: QVar1Id, QVar1Format, {QVar1} and so on.

Example: choose an email recipient dynamically

A document is generated from an opportunity. Instead of hardcoding who receives the emailed document, Docs Made Easy looks up the opportunity's primary contact and emails that person automatically.

  1. Create a query, here called "Fetch Primary Contact", that returns the Contact ID of the opportunity's primary contact. For example, query OpportunityContactRole, filtered to the current opportunity and IsPrimary = true.

    Document query that returns the primary contact of the opportunity

  2. Pass the ID of this query to QVar0Id: in the solution's Assign Behaviors > Other Parameter, add a row with the Parameter Name QVar0Id and the query ID as the Parameter Value.

  3. Reference the result in the email recipient: EmailToId = {QVar0}. In the solution's email settings, this is the To field.

    Email Configurations To field set to {QVar0}

  4. Generate the document. Docs Made Easy emails it to that contact automatically, with no manual recipient selection.

QVar0 retrieves the Contact ID when the document is generated, and EmailToId uses that value to send the document to the right contact.

Example: merge an additional template dynamically

A document is generated from a primary template, but a second template, "Terms and Conditions", must be merged into the same file. A query looks up the "Terms and Conditions" template by name, and its ID is combined with the primary template ID.

  1. Create a query on the Document Template object, filtered to Name = 'Terms and Conditions'. It returns the ID of that template record.

    Document query on Document Template filtered by the Terms and Conditions name

  2. Pass the ID of this query to QVar0Id in Other Parameter, as in the previous example.

  3. Reference the result in documenttemplateId together with the primary template ID, separated by a comma, for example <primary template ID>,{QVar0}. The example also sets MergeDocument to 1.

    Other Parameter list with QVar0Id, documenttemplateId and MergeDocument values

  4. Generate the document. Both templates are merged into a single file.

    Generated document containing the primary template followed by the Terms and Conditions

The query in QVar0Id finds the Document Template record named "Terms and Conditions" and returns its ID, which QVar0 stores. documenttemplateId then resolves to the primary template ID plus {QVar0}, so the generated document contains both the primary template and the "Terms and Conditions" template.

Format the result with QVarFormat

QVarFormat controls how the raw query result is packaged before it's inserted into the rest of the URL. This matters most when a query can return multiple rows, for example several email addresses, rather than a single value.

The format code has six digits:

DigitControlsValues
A (1st)Separator between values1 = comma · 2 = pipe (|) · 3 = semicolon · 4 = colon · 5 = hyphen · other = none
B (2nd)Remove duplicate values1 = remove duplicates · other = keep duplicates
C (3rd)Quotes around each value1 = single quotes · 2 = double quotes · other = no quotes
D (4th)Space after the separator1 = add a space · other = no space
E (5th)Limit each value's length1 = limit to 15 characters · other = keep the full value
F (6th)Wrap the whole result1 = ( ) · 2 = [ ] · 3 = { } · other = no wrapping

For example, if a QVar returns three values (Apple, Orange, Banana):

Format codeMeaning (A–F)Result
100000Comma separator, keep duplicates, no quotes, no space, no length limit, no wrappingApple,Orange,Banana
100100Comma separator and a space, everything else offApple, Orange, Banana

Related: Set up a QVar parameter for dynamic document templates · Merge Document parameter