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 |
-
Create a Salesforce DX project.
-
In your force-app/main/default directory, create a folder for Named Query APIs.
-
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.
-
Add the metadata describing the Named Query API that you’re creating.
See the example later on this page.
-
Deploy the metadata file to your target org.
These options are supported deployment methods:
- Use the Salesforce CLI
deploycommand. 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.
- Use the Salesforce CLI
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).