본문 바로가기

개발자정보

세일즈포스(Salesforce) 오라클(Oracle)에서 SELECT * 같이 조회하기

반응형

ou can use FIELDS() as the complete field list. For example:

  • SELECT FIELDS(ALL) FROM Account LIMIT 200
  • SELECT FIELDS(CUSTOM) FROM Account LIMIT 200
  • SELECT FIELDS(STANDARD) FROM Account

You can also mix FIELDS() with other field names in the field list. For example:

  • SELECT Name, Id, FIELDS(CUSTOM) FROM Account LIMIT 200
  • SELECT someCustomField__c, FIELDS(STANDARD) FROM Account

 

Note

 
 
 
SELECT Id, FIELDS(ALL) FROM User LIMIT 200
 
 
 
HTTP/1.1 400 Bad Request
[
   {
      "message" : "duplicate field selected: Id",
      "errorCode" : "INVALID_FIELD"
   }
]

Subqueries

FIELDS() can also be used in subqueries. For example:

 
 
 
SELECT
   Account.Name, 
   (SELECT FIELDS(ALL) FROM Account.Contacts LIMIT 200)
FROM Account

Support for FIELDS()

FIELDS() is supported in these platform features:

  • Apex
  • The SOQL language wherever query or queryAll operations can be executed.
  • The Salesforce CLI.
  • The /query and /queryAll resources in the Lightning Platform REST API.
  • The query() and queryAll() operations in the Lightning Platform SOAP API.
     

    Note

    When building SOAP API integrations, take care when adopting FIELDS() with grouping options STANDARD, CUSTOM, and ALL.Any change to an org’s object model (such as admin modification, feature enablement, or update via major release) must be immediately reflected in the enterprise WSDL. Otherwise, an error is thrown as the query operation returns a result that doesn’t match the contract with the client.

    Due to its looser coupling to the object model, the partner WSDL isn’t subject to differences between the object model and underlying XML.

  • Query jobs in Bulk API 2.0.
 

Note

For some of these places, there are restrictions on what is supported. See Bounded and Unbounded Queries.

Salesforce CLI Example

This example uses FIELDS() with the Salesforce CLI:

 
 
 
sfdx force:data:soql:query -u DevHub --query "SELECT FIELDS(STANDARD) FROM Account"

(This example assumes that the CLI has been updated to work with version 51.0 or later of the API.)

REST API Example

This request uses FIELDS() with /query in REST API:

 
 
 
GET https://yourInstance.salesforce.com/services/data/v53.0/query?​q=SELECT+FIELDS(STANDARD)+FROM+Account

SOAP API Example

This example uses FIELDS() with query() in SOAP API:

 
 
 
POST https://yourInstance.salesforce.com/services/Soap/c/53.0


   
          
         sessionId
      
   
   
      
         SELECT FIELDS(STANDARD) FROM Account
      
   

Bulk API 2.0 Example

This request uses FIELDS() when creating a bulk query job:

 
 
 
POST https://yourInstance.salesforce.com/services/data/v53.0/jobs/query
{
  "operation": "query",
  "query": "SELECT FIELDS(STANDARD) FROM Account"
}

Bounded and Unbounded Queries

The API distinguishes bounded queries, which have well-defined sets of fields, from unbounded queries, which have sets of fields that the API can’t determine in advance. For example, because the number of custom fields for an object isn’t predetermined, FIELDS(CUSTOM) and FIELDS(ALL) are considered unbounded. This table shows the support for FIELDS() in bounded and unbounded queries:

Bounded – FIELDS(STANDARD)Unbounded – FIELDS(ALL) and FIELDS(CUSTOM)
Apex (inline and dynamic) Supported Not supported
Bulk API 2.0 Supported Not supported
CLI Supported Supported only if the result rows are limited. See Limiting Result Rows.
SOAP API and REST API Supported Supported only if the result rows are limited. See Limiting Result Rows.

Limiting Result Rows

To limit the result rows, you can use add any of these limits to the query:

  • LIMIT n—where n is less than or equal to 200. For example:
     
     
     
    SELECT FIELDS(ALL) FROM Contact LIMIT 200
  • WHERE Id IN idList—where idList is list of up to 200 IDs. For example:
     
     
     
    SELECT FIELDS(ALL) FROM Contact WHERE Id IN ('003R000000ATjnCIAT', '003R000000AZFUIIA5', '003R000000DkYoFIAV')
  • WHERE Id IS idList—where idList is a list of up to 200 ID tests joined with boolean operators. For example:
     
     
     
    SELECT FIELDS(ALL) FROM Contact WHERE Id = '003R000000ATjnCIAT' OR Id = '003R000000AZFUIIA5' OR Id = '003R000000DkYoFIAV'

Notes

  • If you already know which fields you want to retrieve, you’ll get better performance by specifying them explicitly rather than using FIELDS() and retrieving more fields than you need.
  • FIELDS() can cause errors if you use it with operators that require aggregation.
    • For example, without FIELDS() this query works correctly:But adding FIELDS() to the query like thisSELECT FIELDS(ALL), MIN(NumberOfEmployees) FROM Account GROUP BY Id LIMIT 200results in a “Field must be grouped or aggregated” error because it’s equivalent to
    • SELECT IsDeleted, <etc.>, MIN(NumberOfEmployees) FROM Account GROUP BY Id LIMIT 200.
    • SELECT Id, MIN(NumberOfEmployees) FROM Account GROUP BY Id
  • SOQL automatically pages the results if a SELECT statement returns a large amount of data that is expensive to retrieve. This can occur, for example, if the object contains many fields or contains CLOB or BLOB fields. It can also occur if FIELDS() returns a large amount of data. To retrieve all the pages of results, use one of these methods:
    • In Bulk API 2.0, use the Sforce-Locator response header that is returned in the job’s results.
    • In REST API, use the nextRecordsUrl that is returned by /query and /queryAll.
    • In SOAP API, use queryMore().
    • In SOQL, if you use OFFSET and LIMIT in your SOQL query, the number of records returned may be less than LIMIT. Check the number of results that were returned and adjust OFFSET as required. Do not just increment OFFSET by LIMIT.
  • If you use SELECT FIELDS(CUSTOM) on an object that doesn’t have any custom fields, the result is an error:If there are any fields in the field list that do exist, there’s no error. For example, this query returns status code 200 (even if the object contains no custom fields):
  •  
     
     
    SELECT Id, FIELDS(CUSTOM) FROM User LIMIT 200
  •  
     
     
    HTTP/1.1 400 Bad Request
    [ 
       {
          "message": "'FIELDS(...)' expansion function must result in at least one field being selected.",
          "errorCode" : "MALFORMED_QUERY"
       }
    ]
  • The list of fields returned by FIELDS() reflects the current state of the org's metadata and data model. So clients must be prepared to accept different results as the metadata and data model changes. These changes can also affect the performance of the query.
반응형