The pv0 (parameter value zero) parameter makes a document query return only the data related to the record you generate the document from. For example, if a query gathers contacts, you pass the ID of the master record into the pv0 filter. The query then returns only that record's contacts instead of every contact in your org.

How pv0 works

  • Record-specific data. pv0 filters the query to data related to the master record ID, instead of returning all data.
  • Dynamic filters. The filter value comes from the record at generation time, so the data in your documents always matches the current record.

To add a dynamic filter to a query, you must use the pv0 parameter. If a query has more than one dynamic filter, reference the values as pv0, pv1, pv2 and so on.

Create the solution and query

  1. Click the App Launcher (the nine-dot icon at the top left), search for Docs Made Easy and select the app. The Document Setup page opens.

  2. Click Launch Wizard to create a button for your document templates.

  3. Add the solution details, including the name of the button.

    Add Solution Details step with the button name

  4. Click Create New Query. In the window that opens, enter the query details. The Alias field is required. Enter a unique alias for each query, because the template mapping uses it.

    New query window with the required Alias field

  5. Use the search bar to find the fields to include. You can search by field label.

  6. Optionally, add filter conditions in the filter section to narrow down the records the query returns. You can add one or more conditions based on the selected fields.

    Filter section with conditions for the query

  7. Optionally, use Order By to sort the records by a field, such as Created Date or Name, in ascending or descending order. Use Limit to set the maximum number of records to return. For example, to return only the latest record, set the limit to 1.

  8. Click Add Parameter to set up dynamic query filters such as pv0 and pv1. Assign the pv0 value for your query and click Add. In this example, pv0 = Account.Id.

    pv0 parameter set to Account.Id

  9. Click Save, then click Next.

Add the query to a template

  1. Click Create New Document Template to view and use the query syntax. In the window that opens, click Merge Field Helper. It lists the correct merge fields for the queries you created.

  2. Click the SOQL Query Fields tab and select your query.

    SOQL Query Fields tab with the query selected

  3. Copy the table and paste it into your Word template where you want the data to appear, then save the Word template.

    Query table syntax copied from the Merge Field Helper

  4. Click Upload, select your saved Word template, then click Save. Click Next. The Assign Behaviors step opens.

  5. Add the required query parameter, for example the record ID or another specific value. Click Save, then click Next.

    Query parameter added in the Assign Behaviors step

Add the button to the page layout

  1. Click Go to Page Layouts. The page layouts open in a new tab.

  2. Click the layout for your object, in this example Account Layout. The page layout editor opens.

  3. Click Mobile & Lightning Actions and find the button you created.

  4. Drag the button to Salesforce Mobile and Lightning Experience Actions, next to Post, then click Save.

    New button dragged next to Post in Salesforce Mobile and Lightning Experience Actions

Generate the document

  1. Open an account record and click the button you created. The Composer page opens.

  2. Click Download (Template). Docs Made Easy generates the document with the query results.

    Generated document with the query results for the account

Related: Use SOQL queries in Docs Made Easy · Can I filter child relationship records in a template?