Newer Version Available

This content describes an older version of this product. View Latest

Create Named Query APIs in VS Code

In VS Code, you can create a Named Query API and deploy it to your org. In Setup, you can view, edit, and delete the Named Query API.

User Permissions Needed
To work with Named Query API: Allows users to create, read, update and delete Named Query API records
  1. Create a Salesforce DX project.
  2. In your force-app/main/default directory, create a folder for Named Query APIs.
  3. In the new folder, create a file for your Named Query API.
    Name the file by using the format <NamedQueryAPIName>.apiNamedQuery-meta.xml. For example, myNamedQuery.apiNamedQuery.xml.

    The name must begin with a letter. It can contain only alpha-numeric characters.

    Important

  4. Add the metadata describing the Named Query API that you're creating.
    See the example later on this page.
  5. Deploy the metadata file to your target org.
    These options are supported deployment methods:
    • Use the Salesforce CLI deploy command. For example: sf project deploy start -o <TargetOrg>, where <TargetOrg> is the username or alias of the target org.
    • Inside your metadata file, right-click to open a list of Salesforce DX commands. Select Salesforce DX: Deploy This Source to Org.

Example

Here's an example of a valid apiNamedQuery-meta.xml file. You must include these elements:

  • Label (<masterLabel>)
  • Description (<description>)
  • SOQL statement for the Named Query API (<body2>)
The ApiNamedQuery and ApiNamedQueryParameter objects are supported for use with Metadata API (Retrieve and Deploy).