Use SOQL Queries

If you're comfortable with SOQL queries and you want to pull in a custom list of object/records from Salesforce, we have a way for you to write your own queries.

The result of the queries will be a list of records, so you need to setup a loop in your document.  Then in your WebMerge Mapping, you'll find that loop merge field, and you'll select << SOQL Query >> from the dropdown.

Then you'll see a text box where you can enter your query:



Use field values in query

This query can include fields from the main object you're pulling data from in the Mapping (ie the Account record).  Our system will search for this format in the query:


So for example, if you wanted to include the Account's Name in the query you would use:



Default System Fields










Using the query result

The result of this query (ie the data that's sent over to WebMerge) will be in a list/array that you can loop through in your document.  Inside the loop, you'll use the subfields that you queried to print the values.

Here's an example:

{foreach from=$opps item=_row}

Have more questions? Submit a request


  • Avatar
    Priya Y

    For pulling data through SOQL queries, it has been told that we need to set up a loop in the document and then map with <> in Salesforce field mapping.
    Could you provide with the syntax?
    Ex: I have used the loop below in my document
    {foreach from=$contacts item=_con

    But while doing mapping for contacts I am not able to see > in Salesforce fields.

  • Avatar
    Jeremy Clarke

    Hi Supriya,

    In your WebMerge Mapping, next to your "contacts" field, type in "<".

    You may have to upgrade to the latest version of our managed package. This was released last week.


  • Avatar
    Adarsh Singh

    Hi Jeremy,
    I am using SOQL for field mapping, this below SOQL am used to get records.

    SELECT Id, Name, Price_Book__c, Product__c, Price_Book__r.Id, Price_Book__r.Name, Product__r.Id, Product__r.Name, Product__r.Product_Name__c FROM Price_Book_Entry__c where Price_Book__r.Name = :LoopName

    In above image, LoopName is a merge field, mapped with 'Price Book Name'.

    but am not able to get any records due to incorrect filter parameter. can you please let me know the correct way to pass a dynamic value in where clause in SOQL.

    thank you

    Edited by Adarsh Singh
  • Avatar
    Jeremy Clarke

    Hi Adarsh,

    Instead of :LoopName, you need to use the API Field Name for the field that's on the primary object of your mapping (if the field isn't on your primary object, then you'll need to create a new custom field and use a formula to set the value). It should look more something like this:

    SELECT Id, Name, Price_Book__c, Product__c, Price_Book__r.Id, Price_Book__r.Name, Product__r.Id, Product__r.Name, Product__r.Product_Name__c FROM Price_Book_Entry__c where Price_Book__r.Name = ':Loop_Name__c'

  • Avatar
    Gurpreet Kaur

    Hi Jeremy

    I am fetching full name using SOQL query
    Select name from Contact where Id=':Contact__c'

    This is added in Relationship (Custom object) which has master detail relationship with Contact. I am getting data in Merge data while debugging however my output template shows array instead of full name.

    How to fix this?

  • Avatar
    Jeremy Clarke

    Hi Gurpreet,

    When the data is sent over to WebMerge from an SOQL query, it will always send over an array (even if you just select 1 field), so I suggest doing this in your template:


    Then in your WebMerge Mapping you'll put your SOQL next to the "Contact" merge field.


  • Avatar
    Shafqat Ali

    Can the loop or SOQL be done in a PDF document?

  • Avatar
    Jeremy Clarke

    Hi Shafqat,

    You can't use a loop inside a fillable PDF, but you can use static fields using the Field Map ( like this:


  • Avatar
    Carles Massot Cardona


    We have a requirement for which we need the ID of the logged in user. We plan to use in the SOQL query. How can we get this?

  • Avatar
    Jeremy Clarke

    Hi Carles,

    We just released a new version of our app (version 1.240) that supports UserInfo fields like this in your SOQL:


    Please install the latest version of our app from the AppExchange :)

  • Avatar
    Saraswathi D

    Hi ,
    I need to pass object id in the SOQL
    eg : I have a full object TEAM so how to use TEAM.ID(any other field using dot operator) in the SOQL WHERE condition

  • Avatar
    Jeremy Clarke

    Hi Saraswathi,

    Unfortunately, you can only use fields that are on the primary object of your mapping, but you could setup a custom field on that object that references your Team ID field and then use that custom field in your SOQL query.


  • Avatar
    JP Sulit


    I'm trying to do this SOQL query on the WebMerge mapping but it didn't work.

    Query: select id, name from user where id = ':UserInfo.Id'

    Error: SOQL Error: invalid ID field: :UserInfo.Id

    Your help will be greatly appreciated. Thanks!

  • Avatar
    Jeremy Clarke

    Hi JP,

    Actually, you don't need to use a SOQL query to grab the user information. We have a field available called "Current User: (Full Object)" in the field dropdown. You can use it like this:


Please sign in to leave a comment.
Powered by Zendesk