No Results
Search Tips:
- Please consider misspellings
- Try different search keywords
search コール例
次の Java および C# の例では、Partner WSDL の search() コールの使用方法を示します。各例では、SOQL クエリで使用されている電話番号の文字列を受け入れます。search コールでは、すべての取引先責任者、リード、および取引先の電話番号項目の中から、渡された値に一致する項目を検索します。次に、この例では、一致するレコードを含む返された検索結果を反復処理し、配列にそれらを追加し、コンソールにその項目の値を書き込みます。返されたレコード項目は、各レコードタイプの SOQL クエリで指定された項目に対応します。
サンプルメソッドを実行するには、Partner WSDL の使用例で提供されている対応する Java または C# テンプレートクラスを使用できます。
Java の例
1swfobject.registerObject("clippy.codeblock-0", "9");public void searchSample(String phoneNumber) {
2 try {
3 // Example of phoneNumber format: 4155551212
4 String soslQuery =
5 "FIND {" + phoneNumber + "} IN Phone FIELDS " +
6 "RETURNING " +
7 "Contact(Id, Phone, FirstName, LastName), " +
8 "Lead(Id, Phone, FirstName, LastName)," +
9 "Account(Id, Phone, Name)";
10 // Perform SOSL query
11 SearchResult sResult = partnerConnection.search(soslQuery);
12 // Get the records returned by the search result
13 SearchRecord[] records = sResult.getSearchRecords();
14 // Create lists of objects to hold search result records
15 List<SObject> contacts = new ArrayList<SObject>();
16 List<SObject> leads = new ArrayList<SObject>();
17 List<SObject> accounts = new ArrayList<SObject>();
18
19 // Iterate through the search result records
20 // and store the records in their corresponding lists
21 // based on record type.
22 if (records != null && records.length > 0) {
23 for (int i = 0; i < records.length; i++){
24 SObject record = records[i].getRecord();
25 if (record.getType().toLowerCase().equals("contact")) {
26 contacts.add(record);
27 } else if (record.getType().toLowerCase().equals("lead")){
28 leads.add(record);
29 } else if (record.getType().toLowerCase().equals("account")) {
30 accounts.add(record);
31 }
32 }
33 // Display the contacts that the search returned
34 if (contacts.size() > 0) {
35 System.out.println("Found " + contacts.size() +
36 " contact(s):");
37 for (SObject contact : contacts) {
38 System.out.println(contact.getId() + " - " +
39 contact.getField("FirstName") + " " +
40 contact.getField("LastName") + " - " +
41 contact.getField("Phone")
42 );
43 }
44 }
45 // Display the leads that the search returned
46 if (leads.size() > 0) {
47 System.out.println("Found " + leads.size() +
48 " lead(s):");
49 for (SObject lead : leads) {
50 System.out.println(lead.getId() + " - " +
51 lead.getField("FirstName") + " " +
52 lead.getField("LastName") + " - " +
53 lead.getField("Phone")
54 );
55 }
56 }
57 // Display the accounts that the search returned
58 if (accounts.size() > 0) {
59 System.out.println("Found " +
60 accounts.size() + " account(s):");
61 for (SObject account : accounts) {
62 System.out.println(account.getId() + " - " +
63 account.getField("Name") + " - " +
64 account.getField("Phone")
65 );
66 }
67 }
68 } else {
69 // The search returned no records
70 System.out.println("No records were found for the search.");
71 }
72 } catch (ConnectionException ce) {
73 ce.printStackTrace();
74 }
75}C# の例
1swfobject.registerObject("clippy.codeblock-1", "9");public void searchSample(String phoneNumber)
2{
3 try
4 {
5 // Example of phoneNumber format: 4155551212
6 String soslQuery =
7 "FIND {" + phoneNumber + "} IN Phone FIELDS " +
8 "RETURNING " +
9 "Contact(Id, Phone, FirstName, LastName), " +
10 "Lead(Id, Phone, FirstName, LastName)," +
11 "Account(Id, Phone, Name)";
12 // Perform SOSL query
13 SearchResult sResult = binding.search(soslQuery);
14 // Get the records returned by the search result
15 SearchRecord[] records = sResult.searchRecords;
16 // Create lists of objects to hold search result records
17 ArrayList contacts = new System.Collections.ArrayList();
18 ArrayList leads = new System.Collections.ArrayList();
19 ArrayList accounts = new System.Collections.ArrayList();
20
21 // Iterate through the search result records
22 // and store the records in their corresponding lists
23 // based on record type.
24 if ((records != null) && (records.Length > 0))
25 {
26 for (int i = 0; i < records.Length; i++)
27 {
28 sObject record = records[i].record;
29
30 if (record.type.ToLower().Equals("contact"))
31 {
32 contacts.Add(record);
33 }
34 else if (record.type.ToLower().Equals("lead"))
35 {
36 leads.Add(record);
37 }
38 else if (record.type.ToLower().Equals("account"))
39 {
40 accounts.Add(record);
41 }
42 }
43 // Display the contacts that the search returned
44 if (contacts.Count > 0)
45 {
46 Console.WriteLine("Found " + contacts.Count + " contact(s):");
47 for (int i = 0; i < contacts.Count; i++)
48 {
49 sObject c = (sObject)contacts[i];
50 Console.WriteLine(c.Any[0].InnerText + " - " +
51 c.Any[2].InnerText + " " +
52 c.Any[3].InnerText + " - " + c.Any[1].InnerText);
53 }
54 }
55 // Display the leads that the search returned
56 if (leads.Count > 0)
57 {
58 Console.WriteLine("Found " + leads.Count + " lead(s):");
59 for (int i = 0; i < leads.Count; i++)
60 {
61 sObject l = (sObject)leads[i];
62 Console.WriteLine(l.Any[0].InnerText + " - " +
63 l.Any[2].InnerText + " " +
64 l.Any[3].InnerText + " - " + l.Any[1].InnerText);
65 }
66 }
67 // Display the accounts that the search returned
68 if (accounts.Count > 0)
69 {
70 Console.WriteLine("Found " + accounts.Count + " account(s):");
71 for (int i = 0; i < accounts.Count; i++)
72 {
73 sObject a = (sObject)accounts[i];
74 Console.WriteLine(a.Any[0].InnerText + " - " +
75 a.Any[2].InnerText + " - " +
76 a.Any[1].InnerText);
77 }
78 }
79 }
80 else
81 {
82 // The search returned no records
83 Console.WriteLine("No records were found for the search.");
84 }
85 }
86 catch (SoapException e)
87 {
88 Console.WriteLine("An unexpected error has occurred: " + e.Message +
89 " Stack trace: " + e.StackTrace);
90 }
91}