Skip Navigation
Querying custom fields through ROQL
Answer ID 6390   |   Last Review Date 03/18/2019

How do I query for custom fields using ROQL?




In order to query for custom fields through ROQL an ObjectTemplate must be supplied with the query. While the code that will produce a SOAP envelope containing a ROQL query for custom fields can be written differently when using different access points, the resultant SOAP envelope will be similar. Utilizing the QueryObjects call with templating will result in a SOAP envelope like the following:

<s:Envelope xmlns:u='' xmlns:s=''>
    <h:ClientInfoHeader xmlns='' xmlns:xsi='' xmlns:h='' xmlns:xsd=''>
      <AppID>Basic Objects Sample</AppID>
    <o:Security s:mustUnderstand='1' xmlns:o=''>
      <o:UsernameToken u:Id='uuid-84093390-78b8-44db-acba-6a792c0a22a3-1'>
  <s:Body xmlns:xsi='' xmlns:xsd=''>
    <QueryObjects xmlns=''>
      <Query>SELECT Incident FROM Incident WHERE ID = 1</Query>
      <ObjectTemplates xmlns:q1='' xsi:type='q1:Incident'>
        <q1:CustomFields />

The following pages of documentation contain additional information on this topic:
ROQL and Common Objects
ROQL and Custom Objects 

Alternatively, custom fields can be queried for using the QueryCSV function without the use of an object template.


The QueryObjects function is designed to return objects. Custom fields are not objects as they contain only the data type that they are set to (integer, menu, string, etc), so a template must be supplied to apply the custom field information to.