文字列を検索する
SOSL 検索を実行するには、Search リソースを使用し、SOSL を使用しない簡単な RESTful 検索を実行するには、Parameterized Search リソースを使用します。
GET メソッドを使用した SOSL 検索の例
次の例では、Acme の SOSL 検索を実行します。この例の検索文字列は URL 符号化されている必要があります。
- 使用例
-
1curl https://yourInstance.salesforce.com/services/data/v37.0/search/?q=FIND+%7BAcme%7D -H "Authorization: Bearer token" - リクエストボディの例
- 不要
- レスポンスボディの例
-
1{ 2 "searchRecords" : [ { 3 "attributes" : { 4 "type" : "Account", 5 "url" : "/services/data/v35.0/sobjects/Account/001D000000IqhSLIAZ" 6 }, 7 "Id" : "001D000000IqhSLIAZ", 8 }, { 9 "attributes" : { 10 "type" : "Account", 11 "url" : "/services/data/v35.0/sobjects/Account/001D000000IomazIAB" 12 }, 13 "Id" : "001D000000IomazIAB", 14 } ] 15}
GET メソッドを使用した、パラメータ化された検索の例
次の例では、Acme のパラメータ化された検索を実行します。この例の検索文字列は URL 符号化されている必要があります。
- 使用例
- Acme を含むすべての結果のグローバル検索
-
1curl https://yourInstance.salesforce.com/services/data/v37.0/parameterizedSearch/?q=Acme - Acme を含む結果の取引先検索 (ID 項目と名前項目が返される)
-
1curl https://yourInstance.salesforce.com/services/data/v37.0/parameterizedSearch/?q=Acme&sobject=Account&Account.fields=id,name&Account.limit=10 - リクエストボディの例
- 不要
- レスポンスボディの例
-
1{ 2 "searchRecords" : [ { 3 "attributes" : { 4 "type" : "Account", 5 "url" : "/services/data/v35.0/sobjects/Account/001D000000IqhSLIAZ" 6 }, 7 "Id" : "001D000000IqhSLIAZ" 8 }, { 9 "attributes" : { 10 "type" : "Account", 11 "url" : "/services/data/v35.0/sobjects/Account/001D000000IomazIAB" 12 }, 13 "Id" : "001D000000IomazIAB" 14 } ] 15} - metadata パラメータを含むレスポンスボディの例
-
1{ 2 "searchRecords" : [ { 3 "attributes" : { 4 "type" : "Account", 5 "url" : "/services/data/v35.0/sobjects/Account/001D000000IqhSLIAZ" 6 }, 7 "Id" : "001D000000IqhSLIAZ", 8 }, { 9 "attributes" : { 10 "type" : "Account", 11 "url" : "/services/data/v35.0/sobjects/Account/001D000000IomazIAB" 12 }, 13 "Id" : "001D000000IomazIAB", 14 } ], 15 "metadata" : { 16 "entityetadata" : [ { 17 "entityName" : "Account", 18 "fieldMetadata" : [ { 19 20 "name" : "Name", 21 "label" : "Account Name" 22 } ] 23 } ] 24 } 25}
POST メソッドを使用した、パラメータ化された検索の例
使用可能なすべての検索機能にアクセスする POST メソッドを使用してパラメータ化された検索を実行します。
- 使用例
-
1curl https://yourInstance.salesforce.com/services/data/v36.0/parameterizedSearch "Authorization: Bearer token-H "Content-Type: application/json” -d "@search.json” - リクエストボディの例
- 不要
- JSON ファイルの例
-
1{ 2 "q":"Smith", 3 "fields" : ["id", "firstName", "lastName"], 4 "sobjects":[{"fields":["id", "NumberOfEmployees"], 5 "name": "Account", 6 "limit":20}, 7 {"name": "Contact"}], 8 "in":"ALL", 9 "overallLimit":100, 10 "defaultLimit":10 11} - レスポンスボディの例
-
1{ 2 "searchRecords" : [ { 3 "attributes" : { 4 "type" : "Contact", 5 "url" : "/services/data/v36.0/sobjects/Contact/003xx000004TraiAAC" 6 }, 7 "Id" : "003xx000004TraiAAC", 8 "FirstName" : "Smith", 9 "LastName" : "Johnson" 10 }, { 11 "attributes" : { 12 "type" : "Account", 13 "url" : "/services/data/v36.0/sobjects/Account/001xx000003DHXnAAO" 14 }, 15 "Id" : "001xx000003DHXnAAO", 16 "NumberOfEmployees" : 100 17 } ] 18}