Query Objects Examples
AVAILABLE API VERSION API v56.0 and later Optional fields available in API v65.0 and later
Use queries to load record data from Salesforce objects. Only objects supported by UI API are available for querying.
Query an Object
To query an object, request a field with the same name under the RecordQuery type . This example queries accounts with their IDs and names.
1 query accounts {
2 uiapi {
3 query {
4 Account {
5 edges {
6 node {
7 Id
8 Name {
9 value
10 }
11 }
12 }
13 }
14 }
15 }
16 }
The query returns only objects and fields that the user has access to.
1 {
2 "data" : {
3 "uiapi" : {
4 "query" : {
5 "Account" : {
6 "edges" : [
7 {
8 "node" : {
9 "Id" : "0015f000007wCAWAA2" ,
10 "Name" : {
11 "value" : "Enfield Tennis Academy"
12 }
13 }
14 } ,
15 {
16 "node" : {
17 "Id" : "0015f000007vRRVAA2" ,
18 "Name" : {
19 "value" : "Ennet House"
20 }
21 }
22 }
23 ]
24 }
25 }
26 }
27 }
28 }
Query an Object With Optional fields
This example queries users with their IDs and employee numbers. The employee number field is marked as optional.
1 query optional {
2 uiapi {
3 query {
4 User {
5 edges {
6 node {
7 Id
8 EmployeeNumber @optional {
9 value
10 }
11 }
12 }
13 }
14 }
15 }
16 }
If the user executing the query has access to the employee number field, the query returns all the data as expected. If the user executing the query doesn’t have access to the employee number field, the query succeeds and returns the Id field but not the EmployeeNumber field or any subfields of EmployeeNumber.
Query Multiple Objects
You can query multiple objects in one call.
1 uiapi {
2 query {
3 Account { ... }
4 Case { ... }
5 Contact { ... }
6 Opportunity { ... }
7 }
8 }
Send your query in a separate call if the query depends on a field or value from an earlier query. Alternatively, work with semi-joins or auto-joins to query parent and child relationships.
This example queries accounts and cases. The second query includes a semi-join using the reference field AccountId, which filters cases whose account parent records match the given Name pattern and Industry field value.
1 query AccountsAndCases {
2 uiapi {
3 query {
4 Account {
5 edges {
6 node {
7 Name { value }
8 Industry { value }
9 }
10 }
11 }
12 Case ( where : { AccountId : { inq : { Account : {
13 and : [
14 { Name : { like : "United%" } } ,
15 { Industry : { eq : "Energy" } }
16 ] } ,
17 ApiName : "Id" } } } ) {
18 edges {
19 node {
20 AccountId { value }
21 Priority { value }
22 Subject { value }
23 }
24 }
25 }
26 }
27 }
28 }
The query returns the first 10 results of each query.
1 {
2 "data" : {
3 "uiapi" : {
4 "query" : {
5 "Account" : {
6 "edges" : [
7 {
8 "node" : {
9 "Name" : {
10 "value" : "GenePoint"
11 } ,
12 "Industry" : {
13 "value" : "Biotechnology"
14 }
15 }
16 } ,
17 {
18 "node" : {
19 "Name" : {
20 "value" : "United Oil & Gas, UK"
21 } ,
22 "Industry" : {
23 "value" : "Energy"
24 }
25 }
26 } ,
27 {
28 "node" : {
29 "Name" : {
30 "value" : "Edge Communications"
31 } ,
32 "Industry" : {
33 "value" : "Electronics"
34 }
35 }
36 } ,
37 {
38 "node" : {
39 "Name" : {
40 "value" : "United Oil & Gas Corp"
41 } ,
42 "Industry" : {
43 "value" : "Energy"
44 }
45 }
46 } // 6 more results
47 ]
48 } ,
49 "Case" : {
50 "edges" : [
51 {
52 "node" : {
53 "AccountId" : {
54 "value" : "0011a000005slmlAAA"
55 } ,
56 "Priority" : {
57 "value" : "High"
58 } ,
59 "Subject" : {
60 "value" : "Performance inadequate for second consecutive week"
61 }
62 }
63 } ,
64 {
65 "node" : {
66 "AccountId" : {
67 "value" : "0011a000005slmlAAA"
68 } ,
69 "Priority" : {
70 "value" : "High"
71 } ,
72 "Subject" : {
73 "value" : "Seeking guidance on electrical wiring installation for GC5060"
74 }
75 }
76 } ,
77 {
78 "node" : {
79 "AccountId" : {
80 "value" : "0011a000005slmcAAA"
81 } ,
82 "Priority" : {
83 "value" : "Medium"
84 } ,
85 "Subject" : {
86 "value" : "Mechanical maintenance guidelines for generator misleading"
87 }
88 }
89 } ,
90 {
91 "node" : {
92 "AccountId" : {
93 "value" : "0011a000005slmlAAA"
94 } ,
95 "Priority" : {
96 "value" : "High"
97 } ,
98 "Subject" : {
99 "value" : "Design issue with mechanical rotor"
100 }
101 }
102 } // 6 more results
103 ]
104 }
105 }
106 }
107 } ,
108 "errors" : [ ]
109 }
The first query returns accounts with the Name and Industry fields, similar to this SOQL statement.
1 SELECT Name , Industry FROM Account
The second query is similar to this SOQL statement.
1 SELECT AccountId, Priority, Subject
2 FROM Case
3 WHERE AccountId
4 IN (
5 SELECT Id
6 FROM Account
7 WHERE Name LIKE 'United%' and
8 Industry = 'Energy'
9 )
Multiple query execution where a query requires field or value dependencies on another query within the same execution isn’t supported.