{"id":3657,"date":"2023-11-27T17:53:33","date_gmt":"2023-11-27T09:53:33","guid":{"rendered":"http:\/\/www.ponybai.com\/?p=3657"},"modified":"2023-11-21T18:04:38","modified_gmt":"2023-11-21T10:04:38","slug":"soql-%e5%92%8c-sosl-%e6%9f%a5%e8%af%a2","status":"publish","type":"post","link":"http:\/\/www.ponybai.com\/?p=3657","title":{"rendered":"SOQL \u548c SOSL \u67e5\u8be2"},"content":{"rendered":"\n<p>\u60a8\u53ef\u4ee5\u8bc4\u4f30 Salesforce \u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00 \uff08SOQL\uff09 \u6216 Salesforce \u5bf9\u8c61\u641c\u7d22 \u8bed\u8a00 \uff08SOSL\uff09 \u8bed\u53e5\u5728 Apex \u4e2d\u52a8\u6001\uff0c\u65b9\u6cd5\u662f\u5c06\u8bed\u53e5\u62ec\u5728\u6b63\u65b9\u5f62\u4e2d \u62ec\u5f27\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SOQL \u8bed\u53e5<\/h2>\n\n\n\n<p>SOQL \u8bed\u53e5\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a\u65b9\u6cd5\u67e5\u8be2\u7684 sObjects\u3001\u5355\u4e2a sObject \u6216 Integer \u5217\u8868\u3002<samp>count<\/samp>\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u68c0\u7d22\u540d\u4e3a \u9876\u70b9\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Account&gt; aa = &#91;SELECT Id, Name FROM Account WHERE Name = 'Acme'];<\/code><\/pre>\n\n\n\n<p>\u4ece \u6b64\u5217\u8868\uff0c\u60a8\u53ef\u4ee5\u8bbf\u95ee\u4e2a\u4eba \u5143\u7d20\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (!aa.isEmpty()) {\n   \/\/ Execute commands\n}<\/code><\/pre>\n\n\n\n<p>\u60a8\u8fd8\u53ef\u4ee5\u4ece\u73b0\u6709\u5bf9\u8c61\u7684 SOQL \u67e5\u8be2\u521b\u5efa\u65b0\u5bf9\u8c61\u3002\u8fd9\u4e2a\u4f8b\u5b50 \u4e3a\u7b2c\u4e00\u4e2a\u5ba2\u6237\u521b\u5efa\u4e00\u4e2a\u65b0\u8054\u7cfb\u4eba\uff0c\u5176\u5458\u5de5\u6570\u91cf\u8f83\u591a \u6bd4 10.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Contact c = new Contact(Account = &#91;SELECT Name FROM Account \n    WHERE NumberOfEmployees &gt; 10 LIMIT 1]);\nc.FirstName = 'James';\nc.LastName = 'Yoyce';<\/code><\/pre>\n\n\n\n<p>\u8fd9 \u65b0\u521b\u5efa\u7684\u5bf9\u8c61\u5305\u542b\u5176\u5b57\u6bb5\u7684 NULL \u503c\uff0c\u5fc5\u987b\u8bbe\u7f6e\u8fd9\u4e9b\u503c\u3002\u8be5\u65b9\u6cd5\u53ef\u7528\u4e8e\u8fd4\u56de \u67e5\u8be2\u8fd4\u56de\u7684\u884c\u6570\u3002\u4ee5\u4e0b\u793a\u4f8b\u8fd4\u56de\u603b\u6570 \u59d3\u6c0f\u4e3a \u9b4f\u65af\u66fc\uff1a<\/p>\n\n\n\n<p><samp>count<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer i = &#91;SELECT COUNT() FROM Contact WHERE LastName = 'Weissman'];<\/code><\/pre>\n\n\n\n<p>\u4f60 \u4e5f\u53ef\u4ee5\u4f7f\u7528\u6807\u51c6\u5bf9\u7ed3\u679c\u8fdb\u884c\u64cd\u4f5c \u7b97\u672f\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer j = 5 * &#91;SELECT COUNT() FROM Account];<\/code><\/pre>\n\n\n\n<p>\u6267\u884c SOQL \u67e5\u8be2\u65f6\u9002\u7528 SOQL \u9650\u5236\u3002\u8bf7\u53c2\u9605\u6267\u884c\u8c03\u63a7\u5668\u548c\u9650\u5236\u3002<\/p>\n\n\n\n<p>\u6709\u5173 SOQL \u67e5\u8be2\u8bed\u6cd5\u7684\u5b8c\u6574\u8bf4\u660e\uff0c\u8bf7\u53c2\u9605\u00a0Salesforce SOQL \u548c SOSL \u53c2\u8003 \u6307\u5357\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SOSL \u58f0\u660e<\/h2>\n\n\n\n<p>SOSL \u8bed\u53e5\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a sObject \u5217\u8868\uff0c\u5176\u4e2d\u6bcf\u4e2a\u5217\u8868\u90fd\u5305\u542b \u7279\u5b9a sObject \u7c7b\u578b\u7684\u641c\u7d22\u7ed3\u679c\u3002\u59cb\u7ec8\u8fd4\u56de\u7ed3\u679c\u5217\u8868 \u5176\u987a\u5e8f\u4e0e\u5728 SOSL \u67e5\u8be2\u4e2d\u6307\u5b9a\u7684\u987a\u5e8f\u76f8\u540c\u3002\u5982\u679c SOSL \u67e5\u8be2\u6ca1\u6709 \u8fd4\u56de\u6307\u5b9a sObject \u7c7b\u578b\u7684\u4efb\u4f55\u8bb0\u5f55\uff0c\u641c\u7d22\u7ed3\u679c\u4e2d\u5305\u62ec\u4e00\u4e2a\u7a7a\u7684 \u8be5 sObject \u7684\u5217\u8868\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u8fd4\u56de\u5ba2\u6237\u3001\u8054\u7cfb\u4eba\u3001\u5546\u673a\u548c\u6f5c\u5728\u987e\u5ba2\u7684\u5217\u8868 \u4ee5\u77ed\u8bed\u5f00\u5934 \u5730\u56fe\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;List&lt;SObject&gt;&gt; searchList = &#91;FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead];<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610fApex \u4e2d\u5b50\u53e5\u7684\u8bed\u6cd5\u4e0d\u540c\u4e8e SOAP API \u548c REST API \u4e2d\u5b50\u53e5\u7684\u8bed\u6cd5\uff1a<\/p>\n\n\n\n<p><samp>FIND<\/samp><samp>FIND<\/samp><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728 Apex \u4e2d\uff0c\u5b50\u53e5\u7684\u503c\u7528\u5355\u5f15\u53f7\u5206\u9694\u3002\u4e3a \u4f8b\uff1a<samp>FIND<\/samp><code>FIND 'map*' IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead<\/code>\u6ce8\u610f<\/li>\n\n\n\n<li>\u5728 API \u4e2d\uff0c\u5b50\u53e5\u7684\u503c\u7528\u5927\u62ec\u53f7\u5206\u9694\u3002\u4e3a \u4f8b\uff1a<samp>FIND<\/samp><code>FIND {map*} IN ALL FIELDS RETURNING Account (Id, Name), Contact, Opportunity, Lead<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u9876\u70b9 \u5728\u7cfb\u7edf\u6a21\u5f0f\u4e0b\u8fd0\u884c\u4f1a\u5ffd\u7565\u5b57\u6bb5\u7ea7\u5b89\u5168\u6027\uff0c\u800c \u4f7f\u7528 \u626b\u63cf\u5339\u914d\u9879\u3002<samp>IN ALL FIELDS<\/samp>\u4ece \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4e3a \u6bcf\u4e2a\u5bf9\u8c61 \u8fd4\u56de\uff1a<\/p>\n\n\n\n<p><samp>searchList<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Account &#91;] accounts = ((List&lt;Account&gt;)searchList&#91;0]);\nContact &#91;] contacts = ((List&lt;Contact&gt;)searchList&#91;1]);\nOpportunity &#91;] opportunities = ((List&lt;Opportunity&gt;)searchList&#91;2]);\nLead &#91;] leads = ((List&lt;Lead&gt;)searchList&#91;3]);<\/code><\/pre>\n\n\n\n<p>\u6267\u884c SOSL \u67e5\u8be2\u65f6\u9002\u7528 SOSL \u9650\u5236\u3002\u8bf7\u53c2\u9605\u6267\u884c\u8c03\u63a7\u5668\u548c\u9650\u5236\u3002<\/p>\n\n\n\n<p>\u6709\u5173 SOSL \u67e5\u8be2\u8bed\u6cd5\u7684\u5b8c\u6574\u8bf4\u660e\uff0c\u8bf7\u53c2\u9605\u00a0Salesforce SOQL \u548c SOSL \u53c2\u8003 \u6307\u5357\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f7f\u7528 SOQL \u548c SOSL \u67e5\u8be2\u7ed3\u679c<\/li>\n\n\n\n<li>\u901a\u8fc7\u5173\u7cfb\u8bbf\u95ee sObject \u5b57\u6bb5<\/li>\n\n\n\n<li>\u4e86\u89e3\u5916\u952e\u548c\u7236\u5b50\u5173\u7cfb SOQL \u67e5\u8be2<\/li>\n\n\n\n<li>\u4f7f\u7528 SOQL \u805a\u5408\u51fd\u6570<\/li>\n\n\n\n<li>\u4f7f\u7528\u975e\u5e38\u5927\u7684 SOQL \u67e5\u8be2<\/li>\n\n\n\n<li>\u4f7f\u7528\u8fd4\u56de\u4e00\u6761\u8bb0\u5f55\u7684 SOQL \u67e5\u8be2<\/li>\n\n\n\n<li>\u901a\u8fc7\u907f\u514d null \u503c\u6765\u63d0\u9ad8\u6027\u80fd<\/li>\n\n\n\n<li>\u5728 SOQL \u67e5\u8be2<br>\u4e2d\u4f7f\u7528\u591a\u6001\u5173\u7cfb \u591a\u6001\u5173\u7cfb\u662f\u5bf9\u8c61\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u5176\u4e2d\u5f15\u7528\u7684\u5bf9\u8c61\u53ef\u4ee5\u662f\u51e0\u79cd\u4e0d\u540c\u7c7b\u578b\u7684\u7c7b\u578b\u4e4b\u4e00\u3002\u4f8b\u5982\uff0c\u4efb\u52a1\u7684\u5173\u7cfb\u5b57\u6bb5\u53ef\u4ee5\u662f\u8054\u7cfb\u4eba\u6216\u6f5c\u5728\u987e\u5ba2\u3002<samp>Who<\/samp><\/li>\n\n\n\n<li>\u5728 SOQL \u548c SOSL \u67e5\u8be2\u4e2d\u4f7f\u7528 Apex \u53d8\u91cf<\/li>\n\n\n\n<li>\u4f7f\u7528 SOQL \u8bed\u53e5\u67e5\u8be2\u6240\u6709\u8bb0\u5f55<\/li>\n<\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528 SOQL \u548c SOSL \u67e5\u8be2\u7ed3\u679c<\/h1>\n\n\n\n<p>SOQL \u548c SOSL \u67e5\u8be2\u4ec5\u8fd4\u56de sObject \u5b57\u6bb5\u7684\u6570\u636e \u5728\u539f\u59cb\u67e5\u8be2\u4e2d\u88ab\u9009\u4e2d\u3002\u5982\u679c\u60a8\u5c1d\u8bd5\u8bbf\u95ee\u7684\u5b57\u6bb5 \u672a\u5728 SOQL \u6216 SOSL \u67e5\u8be2\u4e2d\u9009\u62e9\uff08ID \u9664\u5916\uff09\uff0c\u60a8\u4f1a\u6536\u5230 \u8fd0\u884c\u65f6\u9519\u8bef\uff0c\u5373\u4f7f\u8be5\u5b57\u6bb5\u5305\u542b\u6570\u636e\u5e93\u4e2d\u7684\u503c\u4e5f\u662f\u5982\u6b64\u3002 \u4e0b\u9762\u7684\u4ee3\u7801\u793a\u4f8b\u4f1a\u5bfc\u81f4\u8fd0\u884c\u65f6\u9519\u8bef\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>insert new Account(Name = 'Singha');\nAccount acc = &#91;SELECT Id FROM Account WHERE Name = 'Singha' LIMIT 1];\n\/\/ Note that name is not selected\nString name = &#91;SELECT Id FROM Account WHERE Name = 'Singha' LIMIT 1].Name;<\/code><\/pre>\n\n\n\n<p>\u4ee5\u4e0b\u662f\u91cd\u5199\u7684\u76f8\u540c\u4ee3\u7801\u793a\u4f8b\uff0c\u56e0\u6b64\u5b83\u4e0d\u4f1a \u4ea7\u751f\u8fd0\u884c\u65f6\u9519\u8bef\u3002\u8bf7\u6ce8\u610f\uff0c\u5df2\u4f5c\u4e3a select \u8bed\u53e5\u7684\u4e00\u90e8\u5206\u6dfb\u52a0\u5728 \u4e4b\u540e\u3002<samp>Name<\/samp><samp>Id<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>insert new Account(Name = 'Singha');\nAccount acc = &#91;SELECT Id FROM Account WHERE Name = 'Singha' LIMIT 1];\n\/\/ Note that name is now selected\nString name = &#91;SELECT Id, Name FROM Account WHERE Name = 'Singha' LIMIT 1].Name;<\/code><\/pre>\n\n\n\n<p>\u5373\u4f7f\u53ea\u9009\u62e9\u4e86\u4e00\u4e2a sObject \u5b57\u6bb5\uff0cSOQL \u6216 SOSL \u67e5\u8be2 \u59cb\u7ec8\u5c06\u6570\u636e\u4f5c\u4e3a\u5b8c\u6574\u8bb0\u5f55\u8fd4\u56de\u3002\u56e0\u6b64\uff0c\u60a8\u5fc5\u987b\u53d6\u6d88\u5f15\u7528 \u8be5\u5b57\u6bb5\u4ee5\u8bbf\u95ee\u5b83\u3002\u4f8b\u5982\uff0c\u6b64\u4ee3\u7801\u68c0\u7d22 \u5e26\u6709 SOQL \u67e5\u8be2\u7684\u6570\u636e\u5e93\u4e2d\u7684 sObject \u5217\u8868\uff0c\u8bbf\u95ee \u5217\u8868\u4e2d\u7684\u7b2c\u4e00\u4e2a\u5ba2\u6237\u8bb0\u5f55\uff0c\u7136\u540e\u53d6\u6d88\u5f15\u7528\u8bb0\u5f55\u7684\u5b57\u6bb5\uff1a<samp>AnnualRevenue<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Double rev = &#91;SELECT AnnualRevenue FROM Account\n              WHERE Name = 'Acme']&#91;0].AnnualRevenue;\n\n\/\/ When only one result is returned in a SOQL query, it is not necessary\n\/\/ to include the list's index.\nDouble rev2 = &#91;SELECT AnnualRevenue FROM Account\n              WHERE Name = 'Acme' LIMIT 1].AnnualRevenue;<\/code><\/pre>\n\n\n\n<p>\u552f\u4e00\u6ca1\u6709\u5fc5\u8981\u53d6\u6d88\u5f15\u7528\u7684\u60c5\u51b5 SOQL \u67e5\u8be2\u7ed3\u679c\u4e2d\u7684 sObject \u5b57\u6bb5\uff0c\u662f\u5f53\u67e5\u8be2 \u8fd4\u56de\u4e00\u4e2a Integer \u4f5c\u4e3a\u64cd\u4f5c\u7684\u7ed3\u679c\uff1a<samp>COUNT<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Integer i = &#91;SELECT COUNT() FROM Account];<\/code><\/pre>\n\n\n\n<p>SOSL \u67e5\u8be2\u8fd4\u56de\u7684\u8bb0\u5f55\u4e2d\u7684\u5b57\u6bb5\u5fc5\u987b\u59cb\u7ec8\u53d6\u6d88\u5f15\u7528\u3002<\/p>\n\n\n\n<p>\u53e6\u8bf7\u6ce8\u610f\uff0c\u5305\u542b\u516c\u5f0f\u7684 sObject \u5b57\u6bb5\u5728 \u53d1\u51fa\u4e86 SOQL \u6216 SOSL \u67e5\u8be2\u3002\u5bf9\u516c\u5f0f\u4e2d\u4f7f\u7528\u7684\u5176\u4ed6\u5b57\u6bb5\u6240\u505a\u7684\u4efb\u4f55\u66f4\u6539\u90fd\u4e0d\u4f1a \u53cd\u6620\u5728\u516c\u5f0f\u5b57\u6bb5\u503c\u4e2d\uff0c\u76f4\u5230\u8bb0\u5f55\u5728 Apex \u4e2d\u4fdd\u5b58\u5e76\u91cd\u65b0\u67e5\u8be2\u3002\u559c\u6b22 \u5176\u4ed6\u53ea\u8bfb sObject \u5b57\u6bb5\uff0c\u5219\u516c\u5f0f\u5b57\u6bb5\u672c\u8eab\u7684\u503c\u4e0d\u80fd\u5728 \u9876\u70b9\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u901a\u8fc7\u5173\u7cfb\u8bbf\u95ee sObject \u5b57\u6bb5<\/h1>\n\n\n\n<p>sObject \u8bb0\u5f55\u8868\u793a\u4e0e\u5176\u4ed6\u8bb0\u5f55\u7684\u5173\u7cfb\uff0c\u5177\u6709\u4e24\u4e2a\u5b57\u6bb5\uff1aID \u548c \u5730\u5740\uff0c\u6307\u5411\u5173\u8054 sObject \u7684\u8868\u793a\u5f62\u5f0f\u3002\u4f8b\u5982\uff0c Contact sObject \u5177\u6709 \u952e\u5165 ID \u548c Account \u7c7b\u578b\u7684\u5b57\u6bb5 \u6307\u5411\u5173\u8054\u7684 sObject \u8bb0\u5f55\u672c\u8eab\u3002<samp>AccountId<\/samp><samp>Account<\/samp><\/p>\n\n\n\n<p>ID \u5b57\u6bb5\u53ef\u7528\u4e8e\u66f4\u6539\u4e0e\u8054\u7cfb\u4eba\u5173\u8054\u7684\u5e10\u6237\uff0c \u800c sObject \u5f15\u7528\u5b57\u6bb5\u53ef\u7528\u4e8e\u8bbf\u95ee\u5e10\u6237\u4e2d\u7684\u6570\u636e\u3002\u8fd9 reference \u5b57\u6bb5\u4ec5\u4f5c\u4e3a SOQL \u6216 SOSL \u67e5\u8be2\u7684\u7ed3\u679c\u8fdb\u884c\u586b\u5145\uff08\u8bf7\u53c2\u9605\u6ce8\u91ca\uff09\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u4ee5\u4e0b Apex \u4ee3\u7801\u663e\u793a\u4e86\u5982\u4f55\u5173\u8054\u5ba2\u6237\u548c\u8054\u7cfb\u4eba \uff0c\u7136\u540e\u5982\u4f55\u4f7f\u7528\u8054\u7cfb\u4eba\u6765\u4fee\u6539 \u5e10\u6237\uff1a<\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u4e3a\u4e86\u63d0\u4f9b\u6700\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u6b64\u4ee3\u7801\u4f7f\u7528\u4e86\u4e00\u4e9b\u63cf\u8ff0\u7684\u5143\u7d20 \u672c\u6307\u5357\u540e\u9762\u90e8\u5206\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6709\u5173 \u548c \u7684\u4fe1\u606f\uff0c\u8bf7\u53c2\u89c1\u00a0Insert\u00a0\u8bed\u53e5\u548c\u00a0Update \u8bed\u53e5\u3002<samp>insertupdate<\/samp><\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>Account a = new Account(Name = 'Acme');\ninsert a;  \/\/ Inserting the record automatically assigns a \n           \/\/ value to its ID field\nContact c = new Contact(LastName = 'Weissman');\nc.AccountId = a.Id;\n\/\/ The new contact now points at the new account\ninsert c;\n\n\/\/ A SOQL query accesses data for the inserted contact, \n\/\/ including a populated c.account field\nc = &#91;SELECT Account.Name FROM Contact WHERE Id = :c.Id];\n\n\/\/ Now fields in both records can be changed through the contact\nc.Account.Name = 'salesforce.com';\nc.LastName = 'Roth';\n\n\/\/ To update the database, the two types of records must be \n\/\/ updated separately\nupdate c;         \/\/ This only changes the contact's last name\nupdate c.Account; \/\/ This updates the account name<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u8868\u8fbe\u5f0f \uff0c\u4ee5\u53ca\u4efb\u4f55\u5176\u4ed6 \u904d\u5386\u5173\u7cfb\u7684\u8868\u8fbe\u5f0f\uff0c\u663e\u793a\u7565\u6709\u4e0d\u540c\u7684\u7279\u5f81 \u5f53\u5b83\u88ab\u8bfb\u53d6\u4e3a\u4e00\u4e2a\u503c\u65f6\uff0c\u800c\u4e0d\u662f\u5f53\u5b83\u88ab\u4fee\u6539\u65f6\uff1a<samp>c.Account.Name<\/samp><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53\u4f5c\u4e3a\u503c\u8bfb\u53d6\u65f6\uff0c\u5982\u679c\u4e3a null\uff0c\u5219\u8ba1\u7b97\u7ed3\u679c\u4e3a \uff0c\u4f46<em>\u4e0d<\/em>\u751f\u6210 .\u6b64\u8bbe\u8ba1\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5bfc\u822a \u591a\u4e2a\u5173\u7cfb\uff0c\u65e0\u9700\u68c0\u67e5 null \u7684\u4e4f\u5473 \u503c\u3002<samp>c.Account<\/samp><samp>c.Account.Name<\/samp><samp>null<\/samp><samp>NullPointerException<\/samp><\/li>\n\n\n\n<li>\u4fee\u6539\u65f6\uff0c\u5982\u679c\u662f null\uff0c\u5219<em>\u751f\u6210<\/em>\u4e00\u4e2a .<samp>c.Account<\/samp><samp>c.Account.Name<\/samp><samp>NullPointerException<\/samp><\/li>\n<\/ul>\n\n\n\n<p>\u5728 SOSL \u4e2d\uff0c\u60a8\u53ef\u4ee5\u4ee5\u4e0e SELECT \u7c7b\u4f3c\u7684\u65b9\u5f0f\u8bbf\u95ee\u63d2\u5165\u7684\u8054\u7cfb\u4eba\u7684\u6570\u636e \u4e0a\u4e00\u4e2a SOQL \u4e2d\u4f7f\u7528\u7684\u8bed\u53e5 \u4f8b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;List&lt;SObject&gt;&gt; searchList = &#91;FIND 'Acme' IN ALL FIELDS RETURNING Contact(id,Account.Name)]<\/code><\/pre>\n\n\n\n<p>\u6b64\u5916\uff0csObject \u5b57\u6bb5\u952e\u53ef\u4ee5\u4e0e \u3001 \u4e00\u8d77\u4f7f\u7528\uff0c\u4e5f\u53ef\u4ee5\u901a\u8fc7\u5916\u90e8 ID \u89e3\u6790\u5916\u952e\u3002\u4e3a \u4f8b\uff1a<samp>insert<\/samp><samp>update<\/samp><samp>upsert<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Account refAcct = new Account(externalId__c = '12345');\n\nContact c = new Contact(Account = refAcct, LastName = 'Kay');\n\ninsert c;<\/code><\/pre>\n\n\n\n<p>\u8fd9\u5c06\u63d2\u5165\u4e00\u4e2a\u5177\u6709\u76f8\u7b49\u7684\u65b0\u8054\u7cfb\u4eba\uff0c\u4ee5\u7b49\u4e8e\u7684\u5e10\u6237 \u5230\u201c12345\u201d\u3002\u5982\u679c\u6ca1\u6709\u6b64\u7c7b\u5e10\u6237\uff0c\u5219\u63d2\u5165\u5931\u8d25\u3002<samp>AccountId<\/samp><samp>external_id<\/samp><\/p>\n\n\n\n<p>\u63d0\u793a<\/p>\n\n\n\n<p>\u4ee5\u4e0b\u4ee3\u7801\u7b49\u6548\u4e8e\u4e0a\u9762\u7684\u4ee3\u7801\u3002\u4f46\u662f\uff0c\u56e0\u4e3a\u5b83\u4f7f\u7528 SOQL \u67e5\u8be2\uff0c\u6548\u7387\u4e0d\u9ad8\u3002\u5982\u679c\u591a\u6b21\u8c03\u7528\u6b64\u4ee3\u7801\uff0c\u5b83\u53ef\u4ee5 \u8fbe\u5230\u6700\u5927 SOQL \u67e5\u8be2\u6570\u7684\u6267\u884c\u9650\u5236\u3002\u67e5\u770b\u66f4\u591a \u6709\u5173\u6267\u884c\u9650\u5236\u7684\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u6267\u884c\u8c03\u63a7\u5668\u548c\u9650\u5236\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Account refAcct = &#91;SELECT Id FROM Account WHERE externalId__c='12345'];\n\nContact c = new Contact(Account = refAcct.Id);\n\ninsert c;<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4e86\u89e3\u5916\u952e\u548c\u7236\u5b50 \u5173\u7cfb SOQL \u67e5\u8be2<\/h1>\n\n\n\n<p>\u58f0\u660e SOQL \u67e5\u8be2\u53ef\u4ee5\u662f\u4efb\u4f55\u6709\u6548\u7684 SOQL \u8bed\u53e5\uff0c\u5305\u62ec\u5916\u952e \u548c\u7236\u5b50\u8bb0\u5f55\u8054\u63a5\u3002\u5982\u679c\u5305\u542b\u5916\u952e\u8054\u63a5\uff0c \u751f\u6210\u7684 sObject \u53ef\u4ee5\u4f7f\u7528\u6b63\u6001\u5b57\u6bb5\u8868\u793a\u6cd5\u8fdb\u884c\u5f15\u7528\u3002 \u4f8b\u5982\uff1a<samp>SELECT<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>System.debug(&#91;SELECT Account.Name FROM Contact\n              WHERE FirstName = 'Caroline'].Account.Name);<\/code><\/pre>\n\n\n\n<p>\u6b64\u5916\uff0csObject \u4e2d\u7684\u7236\u5b50\u5173\u7cfb\u5145\u5f53 SOQL \u67e5\u8be2\u4e5f\u662f\u5982\u6b64\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (Account a : &#91;SELECT Id, Name, (SELECT LastName FROM Contacts)\n                  FROM Account\n                  WHERE Name = 'Acme']) {\n     Contact&#91;] cons = a.Contacts;\n}\n\n\/\/The following example also works because we limit to only 1 contact\nfor (Account a : &#91;SELECT Id, Name, (SELECT LastName FROM Contacts LIMIT 1)\n                  FROM Account\n                  WHERE Name = 'testAgg']) {\n     Contact c = a.Contacts;\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528 SOQL \u805a\u5408\u51fd\u6570<\/h1>\n\n\n\n<p>SOQL \u4e2d\u7684\u805a\u5408\u51fd\u6570\uff08\u5982 \u548c \uff09\u5141\u8bb8\u60a8\u5728\u67e5\u8be2\u4e2d\u6c47\u603b\u548c\u6c47\u603b\u6570\u636e\u3002 \u6709\u5173\u805a\u5408\u51fd\u6570\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u00a0Salesforce SOQL \u548c SOSL \u4e2d\u7684\u805a\u5408\u51fd\u6570 \u53c2\u8003\u6307\u5357\u3002<samp>SUM()MAX()<\/samp><\/p>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u5728\u4e0d\u4f7f\u7528\u5b50\u53e5\u7684\u60c5\u51b5\u4e0b\u4f7f\u7528\u805a\u5408\u51fd\u6570\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u805a\u5408 \u51fd\u6570\u6765\u67e5\u627e\u6240\u6709\u673a\u4f1a\u7684\u5e73\u5747\u91d1\u989d\u3002<samp>GROUP BY<\/samp><samp>AVG()<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AggregateResult&#91;] groupedResults\n  = &#91;SELECT AVG(Amount)aver FROM Opportunity];\nObject avgAmount = groupedResults&#91;0].get('aver');<\/code><\/pre>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u4efb\u4f55\u5305\u542b\u805a\u5408\u51fd\u6570\u7684\u67e5\u8be2\u90fd\u4f1a\u4ee5 AggregateResult \u5bf9\u8c61\u3002AggregateResult \u662f\u53ea\u8bfb sObject\uff0c\u4ec5\u7528\u4e8e\u67e5\u8be2 \u7ed3\u679c\u3002<\/p>\n\n\n\n<p>\u5f53\u60a8\u5c06\u805a\u5408\u51fd\u6570\u4e0e\u5b50\u53e5\u4e00\u8d77\u4f7f\u7528\u65f6\uff0c\u5b83\u4eec\u5c06\u6210\u4e3a\u751f\u6210\u62a5\u544a\u7684\u66f4\u5f3a\u5927\u7684\u5de5\u5177\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u6309\u5e7f\u544a\u7cfb\u5217\u627e\u5230\u6240\u6709\u5546\u673a\u7684\u5e73\u5747\u91d1\u989d\u3002<samp>GROUP BY<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>AggregateResult&#91;] groupedResults\n  = &#91;SELECT CampaignId, AVG(Amount)\n      FROM Opportunity\n      GROUP BY CampaignId];\nfor (AggregateResult ar : groupedResults)  {\n    System.debug('Campaign ID' + ar.get('CampaignId'));\n    System.debug('Average amount' + ar.get('expr0'));\n}<\/code><\/pre>\n\n\n\n<p>\u5217\u8868\u4e2d\u6ca1\u6709 \u522b\u540d\u4f1a\u81ea\u52a8\u83b7\u53d6\u4e00\u4e2a\u9690\u542b\u7684\u522b\u540d\uff0c\u5176\u683c\u5f0f\u4e3a \uff0c\u5176\u4e2d\u8868\u793a \u6ca1\u6709\u663e\u5f0f\u522b\u540d\u7684\u805a\u5408\u5b57\u6bb5\u3002\u7684\u503c\u4ece 0 \u5f00\u59cb\uff0c\u5e76\u4e14 \u6bcf\u4e2a\u805a\u5408\u5b57\u6bb5\u7684\u589e\u91cf\uff0c\u6ca1\u6709\u663e\u5f0f\u522b\u540d\u3002\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u5728 Salesforce SOQL \u548c SOSL \u4e2d\u5c06\u522b\u540d\u4e0e\u00a0<samp>GROUP BY<\/samp>\u00a0\u7ed3\u5408\u4f7f\u7528\u00a0\u53c2\u8003\u6307\u5357\u3002<\/p>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5305\u542b\u805a\u5408\u51fd\u6570\u7684\u67e5\u8be2\u4ecd\u53d7 \u67e5\u8be2\u884c\u3002\u9664\u6bcf\u4e2a\u51fd\u6570\u4e4b\u5916\u7684\u6240\u6709\u805a\u5408\u51fd\u6570\uff0c\u6216\u5305\u62ec\u6bcf\u4e2a\u805a\u5408\u51fd\u6570 \u805a\u5408\u7528\u4f5c\u67e5\u8be2\u884c\u7684\u884c\uff0c\u7528\u4e8e\u9650\u5236\u8ddf\u8e2a\u3002<samp>COUNT()<\/samp><samp>COUNT(fieldname)<\/samp><\/p>\n\n\n\n<p>\u5bf9\u4e8e \u6216 \u67e5\u8be2\uff0c\u9650\u5236\u8ba1\u4e3a\u4e00\u4e2a\u67e5\u8be2\u884c\uff0c\u9664\u975e\u67e5\u8be2 \u5305\u542b\u4e00\u4e2a GROUP BY \u5b50\u53e5\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u6bcf\u4e2a\u5206\u7ec4\u4f7f\u7528\u4e00\u4e2a\u67e5\u8be2\u884c\u3002<samp>COUNT()<\/samp><samp>COUNT(fieldname)<\/samp><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528\u975e\u5e38\u5927\u7684 SOQL \u67e5\u8be2<\/h1>\n\n\n\n<p>\u91cd\u8981<\/p>\n\n\n\n<p>\u5728\u53ef\u80fd\u7684\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u66f4\u6539\u4e86\u975e\u5305\u5bb9\u6027\u6761\u6b3e\uff0c\u4ee5\u7b26\u5408\u6211\u4eec\u7684 \u5e73\u7b49\u7684\u516c\u53f8\u4ef7\u503c\u89c2\u3002\u6211\u4eec\u4fdd\u7559\u4e86\u67d0\u4e9b\u6761\u6b3e\uff0c\u4ee5\u907f\u514d\u5bf9\u5ba2\u6237\u4ea7\u751f\u4efb\u4f55\u5f71\u54cd \u5b9e\u73b0\u3002<\/p>\n\n\n\n<p>SOQL \u67e5\u8be2\u6709\u65f6\u4f1a\u8fd4\u56de\u5982\u6b64\u591a\u7684 sObject\uff0c\u4ee5\u81f3\u4e8e\u5806\u5927\u5c0f\u9650\u5236\u4e3a \u8d85\u51fa\u5e76\u53d1\u751f\u9519\u8bef\u3002\u8981\u89e3\u51b3\u6b64\u95ee\u9898\uff0c\u8bf7\u6539\u7528 SOQL \u67e5\u8be2\u5faa\u73af\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u5904\u7406\u591a\u4e2a \u4f7f\u7528\u5bf9 \u548c \u7684\u5185\u90e8\u8c03\u7528\u5bf9\u8bb0\u5f55\u8fdb\u884c\u6279\u5904\u7406\u3002<samp>for<\/samp><samp>query<\/samp><samp>queryMore<\/samp><\/p>\n\n\n\n<p>\u4f8b\u5982\uff0c\u5982\u679c\u7ed3\u679c\u592a\u5927\uff0c\u5219\u4ee5\u4e0b\u8bed\u6cd5\u4f1a\u5bfc\u81f4\u8fd0\u884c\u65f6\u5f02\u5e38\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Account&#91;] accts = &#91;SELECT Id FROM Account];<\/code><\/pre>\n\n\n\n<p>\u8bf7\u6539\u7528 SOQL \u67e5\u8be2\u5faa\u73af\uff0c\u5982\u4ee5\u4e0b \u4ee5\u4e0b\u793a\u4f8b\uff1a<samp>for<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Use this format if you are not executing DML statements \n\/\/ within the for loop\nfor (Account a : &#91;SELECT Id, Name FROM Account \n                  WHERE Name LIKE 'Acme%']) {\n    \/\/ Your code without DML statements here\n}\n\n\/\/ Use this format for efficiency if you are executing DML statements \n\/\/ within the for loop\nfor (List&lt;Account&gt; accts : &#91;SELECT Id, Name FROM Account\n                            WHERE Name LIKE 'Acme%']) {\n    for (Account a : accts) {\n    \/\/ Your code here\n    }\n    update accts;\n}<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<p>\u5728\u5faa\u73af\u4e2d\u4f7f\u7528 SOQL \u67e5\u8be2 \u964d\u4f4e\u4e86\u8fbe\u5230\u5806\u5927\u5c0f\u9650\u5236\u7684\u53ef\u80fd\u6027\u3002\u4f46\u662f\uff0c\u8fd9\u79cd\u65b9\u6cd5\u53ef\u4ee5 \u5bfc\u81f4 DML \u8c03\u7528\u589e\u52a0\uff0c\u5bfc\u81f4\u4f7f\u7528\u7684 CPU \u5468\u671f\u66f4\u591a\u3002\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 SOQL\u00a0For \u5faa\u73af\u4e0e\u6807\u51c6 SOQL \u67e5\u8be2\u3002<samp>for<\/samp><\/p>\n\n\n\n<p>\u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u4e86\u7528\u4e8e\u6279\u91cf\u66f4\u65b0\u8bb0\u5f55\u7684 SOQL \u67e5\u8be2\u5faa\u73af\u3002\u5047\u8bbe\u4f60\u60f3 \u5728\u8bb0\u5f55\u4e2d\u66f4\u6539\u5176\u540d\u5b57\u548c\u59d3\u6c0f\u7684\u8054\u7cfb\u4eba\u7684\u8054\u7cfb\u4eba\u7684\u59d3\u6c0f \u5339\u914d\u6307\u5b9a\u6761\u4ef6\uff1a<samp>for<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public void massUpdate() {\n    for (List&lt;Contact&gt; contacts:\n      &#91;SELECT FirstName, LastName FROM Contact]) {\n        for(Contact c : contacts) {\n            if (c.FirstName == 'Barbara' &amp;&amp;\n              c.LastName == 'Gordon') {\n                c.LastName = 'Wayne';\n            }\n        }\n        update contacts;\n    }\n}<\/code><\/pre>\n\n\n\n<p>\u4e0d\u662f\u5728\u5faa\u73af\u4e2d\u4f7f\u7528 SOQL \u67e5\u8be2\uff0c\u800c\u662f \u6279\u91cf\u66f4\u65b0\u8bb0\u5f55\u7684\u9996\u9009\u65b9\u6cd5\u662f\u4f7f\u7528\u6279\u5904\u7406 Apex\uff0c\u8fd9\u6837\u53ef\u4ee5\u6700\u5927\u9650\u5ea6\u5730\u964d\u4f4e\u8fbe\u5230\u8c03\u901f\u5668\u9650\u5236\u7684\u98ce\u9669\u3002<samp>for<\/samp><\/p>\n\n\n\n<p>\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u00a0SOQL For \u5faa\u73af\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>\u66f4\u9ad8\u6548\u7684 SOQL \u67e5\u8be2<\/h2>\n\n\n\n<p>\u4e3a\u4e86\u83b7\u5f97\u6700\u4f73\u6027\u80fd\uff0cSOQL \u67e5\u8be2\u5fc5\u987b\u662f\u6709\u9009\u62e9\u6027\u7684\uff0c\u5c24\u5176\u662f\u5bf9\u4e8e\u5185\u90e8\u7684\u67e5\u8be2 \u89e6\u53d1\u5668\u3002\u4e3a\u4e86\u907f\u514d\u957f\u65f6\u95f4\u7684\u6267\u884c\uff0c\u7cfb\u7edf\u53ef\u4ee5\u7ec8\u6b62\u975e\u9009\u62e9\u6027 SOQL \u67e5\u8be2\u3002\u5f53\u89e6\u53d1\u5668\u4e2d\u7684\u975e\u9009\u62e9\u6027\u67e5\u8be2\u65f6\uff0c\u5f00\u53d1\u4eba\u5458\u4f1a\u6536\u5230\u9519\u8bef\u6d88\u606f \u5bf9\u5305\u542b\u8d85\u8fc7 100 \u4e07\u6761\u8bb0\u5f55\u7684\u5bf9\u8c61\u6267\u884c\u3002\u4e3a\u4e86\u907f\u514d\u8fd9\u79cd\u60c5\u51b5 \u9519\u8bef\uff0c\u8bf7\u786e\u4fdd\u67e5\u8be2\u662f\u6709\u9009\u62e9\u6027\u7684\u3002\u9009\u62e9\u6027 SOQL \u67e5\u8be2\u6761\u4ef6<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5f53\u5176\u4e2d\u4e00\u4e2a\u67e5\u8be2\u7b5b\u9009\u5668\u4f4d\u4e8e\u7d22\u5f15\u4e0a\u65f6\uff0c\u67e5\u8be2\u662f\u6709\u9009\u62e9\u6027\u7684 \u5b57\u6bb5\u548c\u67e5\u8be2\u7b5b\u9009\u5668\u4f1a\u51cf\u5c11\u751f\u6210\u7684\u884c\u6570 \u4f4e\u4e8e\u7cfb\u7edf\u5b9a\u4e49\u7684\u9608\u503c\u3002SOQL \u67e5\u8be2\u7684\u6027\u80fd \u6539\u8fdb\u4e86\u5f53 WHERE \u5b50\u53e5\u4e2d\u4f7f\u7528\u7684\u4e24\u4e2a\u6216\u591a\u4e2a\u8fc7\u6ee4\u5668\u6ee1\u8db3 \u63d0\u5230\u7684\u6761\u4ef6\u3002<\/li>\n\n\n\n<li>\u9009\u62e9\u6027\u9608\u503c\u4e3a\u524d 100 \u4e07\u6761\u8bb0\u5f55\u7684 10%\uff0c\u5e76\u4e14 \u5728\u524d 100 \u4e07\u6761\u8bb0\u5f55\u4e4b\u540e\uff0c\u5c11\u4e8e 5% \u7684\u8bb0\u5f55\uff0c\u6700\u591a \u6700\u591a 333,333 \u6761\u8bb0\u5f55\u3002\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u4f8b\u5982 \u4f5c\u4e3a\u7d22\u5f15\u6807\u51c6\u5b57\u6bb5\u7684\u67e5\u8be2\u7b5b\u9009\u5668\uff0c\u9608\u503c\u53ef\u4ee5 \u66f4\u9ad8\u3002\u6b64\u5916\uff0c\u9009\u62e9\u6027\u9608\u503c\u53d7\u4ee5\u4e0b\u56e0\u7d20\u7684\u5f71\u54cd \u6539\u53d8\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u9009\u62e9\u6027 SOQL \u67e5\u8be2\u7684\u81ea\u5b9a\u4e49\u7d22\u5f15\u6ce8\u610f\u4e8b\u9879<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u4ee5\u4e0b\u5b57\u6bb5\u5df2\u7f16\u5236\u7d22\u5f15\u3002\n<ul class=\"wp-block-list\">\n<li>\u4e3b\u952e\uff08Id\u3001Name \u548c OwnerId \u5b57\u6bb5\uff09<\/li>\n\n\n\n<li>\u5916\u952e\uff08\u67e5\u627e\u6216\u4e3b\u4ece\u5173\u7cfb \u5b57\u6bb5\uff09<\/li>\n\n\n\n<li>\u5ba1\u6838\u65e5\u671f\uff08CreatedDate \u548c SystemModstamp \u5b57\u6bb5\uff09<\/li>\n\n\n\n<li>RecordType \u5b57\u6bb5\uff08\u4e3a\u4ee5\u4e0b\u6240\u6709\u6807\u51c6\u5bf9\u8c61\u7f16\u5236\u7d22\u5f15 \u7279\u8272\u4ed6\u4eec\uff09<\/li>\n\n\n\n<li>\u6807\u8bb0\u4e3a\u201c\u5916\u90e8 ID\u201d\u6216\u201c\u552f\u4e00\u201d\u7684\u81ea\u5b9a\u4e49\u5b57\u6bb5<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\u672a\u7f16\u5236\u7d22\u5f15\u7684\u5b57\u6bb5\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u81ea\u52a8\u7f16\u5236\u7d22\u5f15 Salesforce Optimizer \u8ba4\u8bc6\u5230\u7d22\u5f15\u53ef\u4ee5\u6539\u8fdb \u9891\u7e41\u8fd0\u884c\u67e5\u8be2\u7684\u6027\u80fd\u3002<\/li>\n\n\n\n<li>Salesforce \u652f\u6301\u53ef\u4ee5\u6839\u636e\u8bf7\u6c42\u6dfb\u52a0\u81ea\u5b9a\u4e49\u7d22\u5f15 \u5ba2\u6237\u3002<\/li>\n\n\n\n<li>\u65e0\u6cd5\u5728\u4ee5\u4e0b\u7c7b\u578b\u7684\u5b57\u6bb5\u4e0a\u521b\u5efa\u81ea\u5b9a\u4e49\u7d22\u5f15\uff1a \u591a\u9009\u9009\u62e9\u5217\u8868\uff0c\u591a\u5e01\u79cd\u4e2d\u7684\u8d27\u5e01\u5b57\u6bb5 \u7ec4\u7ec7\u3001\u957f\u6587\u672c\u5b57\u6bb5\u3001\u67d0\u4e9b\u516c\u5f0f\u5b57\u6bb5\u548c\u4e8c\u8fdb\u5236\u6587\u4ef6 \u5b57\u6bb5\uff08Blob\u3001\u6587\u4ef6\u6216\u52a0\u5bc6\u6587\u672c\u7c7b\u578b\u7684\u5b57\u6bb5\u3002\u65b0\u6570\u636e \u7c7b\u578b\uff0c\u901a\u5e38\u662f\u590d\u6742\u7684\u7c7b\u578b\uff0c\u4f1a\u5b9a\u671f\u6dfb\u52a0\u5230 Salesforce\uff0c \u8fd9\u4e9b\u7c7b\u578b\u7684\u5b57\u6bb5\u5e76\u4e0d\u603b\u662f\u5141\u8bb8\u81ea\u5b9a\u4e49\u7d22\u5f15\u3002<\/li>\n\n\n\n<li>\u60a8\u65e0\u6cd5\u5728\u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\u7684\u516c\u5f0f\u5b57\u6bb5\u4e0a\u521b\u5efa\u81ea\u5b9a\u4e49\u7d22\u5f15 \u5bf9\u9009\u62e9\u5217\u8868\u5b57\u6bb5\u7684\u51fd\u6570\u8c03\u7528\u3002<samp>TEXT<\/samp><\/li>\n\n\n\n<li>\u901a\u5e38\uff0c\u5728\u8fd9\u4e9b\u60c5\u51b5\u4e0b\u4e0d\u4f7f\u7528\u81ea\u5b9a\u4e49\u7d22\u5f15\u3002<ul><li>\u67e5\u8be2\u7684\u503c\u8d85\u8fc7\u7cfb\u7edf\u5b9a\u4e49\u7684\u9608\u503c\u3002<\/li><li>filter \u8fd0\u7b97\u7b26\u4e3a\u8d1f\u8fd0\u7b97\u7b26\uff0c\u4f8b\u5982 \uff08\u6216 \uff09\u3001 \u548c \u3002<samp>NOT EQUAL TO<\/samp><samp>!=<\/samp><samp>NOT CONTAINS<\/samp><samp>NOT STARTS WITH<\/samp><\/li><li>\u8fd0\u8425\u5546 \u5728\u8fc7\u6ee4\u5668\u4e2d\u4f7f\u7528\uff0c\u4ee5\u53ca\u8981\u626b\u63cf\u7684\u884c\u6570 \u8d85\u8fc7 333,333 \u4eba\u3002\u64cd\u4f5c\u5458\u9700\u8981\u5bf9 \u6307\u6570\u3002\u6b64\u9608\u503c\u53ef\u80fd\u4f1a\u53d1\u751f\u53d8\u5316\u3002<samp>CONTAINS<\/samp><samp>CONTAINS<\/samp><\/li><li>\u60a8\u6b63\u5728\u4e0e\u7a7a\u503c \uff08\uff09 \u8fdb\u884c\u6bd4\u8f83\u3002<samp>Name != &#8221;<\/samp><\/li><\/ul>\u4f46\u662f\uff0c\u8fd8\u6709\u5176\u4ed6\u590d\u6742\u7684\u65b9\u6848\uff0c\u5176\u4e2d\u81ea\u5b9a\u4e49 \u4e0d\u80fd\u4f7f\u7528\u7d22\u5f15\u3002\u5982\u679c\u51fa\u73b0\u4ee5\u4e0b\u60c5\u51b5\uff0c\u8bf7\u8054\u7cfb\u60a8\u7684 Salesforce \u4ee3\u8868 \u8fd9\u4e9b\u60c5\u51b5\u672a\u6db5\u76d6\u4f60\u7684\u65b9\u6848\uff0c\u6216\u8005\u5982\u679c\u9700\u8981 \u5bf9\u975e\u9009\u62e9\u6027\u67e5\u8be2\u7684\u8fdb\u4e00\u6b65\u5e2e\u52a9\u3002<\/li>\n<\/ul>\n\n\n\n<p>\u9009\u62e9\u6027 SOQL \u67e5\u8be2\u7684\u793a\u4f8b\u4e3a\u4e86\u66f4\u597d\u5730\u4e86\u89e3\u5bf9\u5927\u578b\u5bf9\u8c61\u7684\u67e5\u8be2\u662f\u5426\u5177\u6709\u9009\u62e9\u6027\uff0c \u8ba9\u6211\u4eec\u5206\u6790\u4e00\u4e9b\u67e5\u8be2\u3002\u5bf9\u4e8e\u8fd9\u4e9b\u67e5\u8be2\uff0c\u5047\u8bbe\u6709\u66f4\u591a \u5e10\u6237 sObject \u7684 100 \u4e07\u6761\u8bb0\u5f55\u3002\u8fd9\u4e9b\u8bb0\u5f55\u5305\u62ec \u8f6f\u5220\u9664\u7684\u8bb0\u5f55\uff0c\u5373\u4ecd\u5728\u56de\u6536\u4e2d\u7684\u5df2\u5220\u9664\u8bb0\u5f55 \u7ad9\u3002\u67e5\u8be2 1\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT Id FROM Account WHERE Id IN (&lt;list of account IDs&gt;)<\/code><\/pre>\n\n\n\n<p>\u8be5\u5b50\u53e5\u4f4d\u4e8e\u7d22\u5f15\u4e0a \u5b57\u6bb5 \uff08Id\uff09\u3002\u5982\u679c\u8fd4\u56de\u66f4\u5c11 \u8bb0\u5f55\u8d85\u8fc7\u9009\u62e9\u6027\u9608\u503c\u65f6\uff0c\u5219\u4f7f\u7528\u7d22\u5f15 on\u3002\u8be5\u6307\u6570\u901a\u5e38\u4e3a \u5f53 ID \u5217\u8868\u4ec5\u5305\u542b\u51e0\u6761\u8bb0\u5f55\u65f6\u4f7f\u7528\u3002<samp>WHERE<\/samp><samp>SELECT COUNT() FROM Account WHERE Id IN (&lt;list of account IDs&gt;)<\/samp><samp>Id<\/samp>\u67e5\u8be2 2\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT Id FROM Account WHERE Name != ''<\/code><\/pre>\n\n\n\n<p>\u56e0\u4e3a Account \u662f\u4e00\u4e2a\u5927\u5bf9\u8c61\uff0c\u5373\u4f7f Name \u5df2\u7f16\u5236\u7d22\u5f15\uff08\u4e3b\u952e\uff09\uff0c \u6b64\u7b5b\u9009\u5668\u8fd4\u56de\u5927\u90e8\u5206\u8bb0\u5f55\uff0c\u8fdb\u884c\u67e5\u8be2 \u975e\u9009\u62e9\u6027\u3002\u67e5\u8be2 3\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT Id FROM Account WHERE Name != '' AND CustomField__c = 'ValueA'<\/code><\/pre>\n\n\n\n<p>\u8fd9\u91cc \u6211\u4eec\u5fc5\u987b\u770b\u770b\u662f\u5426\u6709\u4efb\u4f55\u8fc7\u6ee4\u5668\uff0c\u5f53\u5355\u72ec\u8003\u8651\u65f6\uff0c\u662f \u9009\u62e9\u6027\u3002\u6b63\u5982\u6211\u4eec\u5728\u524d\u9762\u7684\u793a\u4f8b\u4e2d\u770b\u5230\u7684\uff0c\u7b2c\u4e00\u4e2a\u7b5b\u9009\u5668\u4e0d\u662f \u9009\u62e9\u6027\u3002\u56e0\u6b64\uff0c\u8ba9\u6211\u4eec\u5173\u6ce8\u7b2c\u4e8c\u4e2a\u95ee\u9898\u3002\u5982\u679c\u8bb0\u5f55\u8ba1\u6570 \u8fd4\u56de\u7684 by \u4f4e\u4e8e \u9009\u62e9\u6027\u9608\u503c\uff0cCustomField__c\u7f16\u5236\u7d22\u5f15\uff0c\u5219\u67e5\u8be2\u4e3a \u9009\u62e9\u6027\u3002<samp>SELECT COUNT() FROM Account WHERE CustomField__c = &#8216;ValueA&#8217;<\/samp><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528\u8fd4\u56de\u4e00\u6761\u8bb0\u5f55\u7684 SOQL \u67e5\u8be2<\/h1>\n\n\n\n<p>\u5f53\u7ed3\u679c\u5217\u8868\u4ec5\u5305\u542b\u4e00\u4e2a sObject \u503c\u65f6\uff0c\u53ef\u4ee5\u4f7f\u7528 SOQL \u67e5\u8be2\u6765\u5206\u914d\u5355\u4e2a sObject \u503c \u5143\u7d20\u3002\u5f53\u8868\u8fbe\u5f0f\u7684 L \u503c\u4e3a\u5355\u4e2a sObject \u7c7b\u578b\u65f6\uff0cApex \u4f1a\u81ea\u52a8\u5c06 \u67e5\u8be2\u7ed3\u679c\u5217\u8868\u4e2d\u7684\u5355\u4e2a sObject \u8bb0\u5f55\u4e3a L \u503c\u3002\u5982\u679c\u4e3a\u96f6\uff0c\u5219\u4f1a\u5bfc\u81f4\u8fd0\u884c\u65f6\u5f02\u5e38 \u5728\u5217\u8868\u4e2d\u627e\u5230 sObject \u6216\u591a\u4e2a sObject\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Account&gt; accts = &#91;SELECT Id FROM Account];\n\n\/\/ These lines of code are only valid if one row is returned from\n\/\/ the query. Notice that the second line dereferences the field from the\n\/\/ query without assigning it to an intermediary sObject variable.\nAccount acct = &#91;SELECT Id FROM Account];\nString name = &#91;SELECT Name FROM Account].Name;<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u901a\u8fc7\u907f\u514d null \u503c\u6765\u63d0\u9ad8\u6027\u80fd<\/h1>\n\n\n\n<p>\u5728 SOQL \u548c SOSL \u67e5\u8be2\u4e2d\uff0c\u663e\u5f0f\u7b5b\u9009\u51fa WHERE \u5b50\u53e5\u5141\u8bb8 Salesforce \u63d0\u9ad8\u67e5\u8be2\u6027\u80fd\u3002\u5728\u4ee5\u4e0b\u793a\u4f8b\u4e2d\uff0c \u503c\u4e3a null \u7684\u4efb\u4f55\u8bb0\u5f55\u90fd\u662f \u4ece \u641c\u7d22\u3002<\/p>\n\n\n\n<p><samp>Thread__c<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Public class TagWS {\n\n\/* getThreadTags\n*\n* a quick method to pull tags not in the existing list\n*\n*\/\n   public static webservice List&lt;String&gt; \n   getThreadTags(String threadId, List&lt;String&gt; tags) {\n\n      system.debug(LoggingLevel.Debug,tags);\n\n      List&lt;String&gt; retVals = new List&lt;String&gt;();\n      Set&lt;String&gt; tagSet = new Set&lt;String&gt;();\n      Set&lt;String&gt; origTagSet = new Set&lt;String&gt;();\n      origTagSet.addAll(tags);\n\n\/\/ Note WHERE clause optimizes search where Thread__c is not null\n\n      for(CSO_CaseThread_Tag__c t : \n         &#91;SELECT Name FROM CSO_CaseThread_Tag__c \n         WHERE Thread__c = :threadId AND\n         Thread__c != null]) \n\n      {\n         tagSet.add(t.Name);\n      }\n      for(String x : origTagSet) { \n   \/\/ return a minus version of it so the UI knows to clear it\n         if(!tagSet.contains(x)) retVals.add('-' + x);\n      }\n      for(String x : tagSet) { \n   \/\/ return a plus version so the UI knows it's new\n         if(!origTagSet.contains(x)) retvals.add('+' + x);\n      }\n\n      return retVals;\n   }\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u5728 SOQL \u67e5\u8be2\u4e2d\u4f7f\u7528\u591a\u6001\u5173\u7cfb<\/h1>\n\n\n\n<p>\u591a\u6001\u5173\u7cfb\u662f\u5bf9\u8c61\u4e4b\u95f4\u7684\u5173\u7cfb\uff0c\u5176\u4e2d\u5f15\u7528 \u5bf9\u8c61\u53ef\u4ee5\u662f\u51e0\u79cd\u4e0d\u540c\u7684\u7c7b\u578b\u4e4b\u4e00\u3002\u4f8b\u5982\uff0c\u4efb\u52a1\u7684\u5173\u7cfb\u5b57\u6bb5\u53ef\u4ee5\u662f\u8054\u7cfb\u4eba\u6216\u6f5c\u5728\u987e\u5ba2\u3002<\/p>\n\n\n\n<p><samp>Who<\/samp><\/p>\n\n\n\n<p>\u5728Apex\u4e2d\u4f7f\u7528\u5177\u6709\u591a\u6001\u5173\u7cfb\u7684SOQL\u67e5\u8be2\u7684\u65b9\u6cd5\u5982\u4e0b\u3002 \u5982\u679c\u9700\u8981\u6709\u5173\u591a\u6001\u5173\u7cfb\u7684\u66f4\u591a\u5e38\u89c4\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u4e86\u89e3\u5173\u7cfb\u5b57\u6bb5\u548c\u00a0SOQL \u548c SOSL \u5f15\u7528\u4e2d\u7684\u591a\u6001\u5b57\u6bb5\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u5f15\u7528 Apex \u4e2d\u7684\u591a\u6001\u5b57\u6bb5\u7684 SOQL \u67e5\u8be2\u6765\u83b7\u53d6\u4ee5\u4e0b\u7ed3\u679c\uff1a \u53d6\u51b3\u4e8e\u591a\u6001\u5b57\u6bb5\u5f15\u7528\u7684\u5bf9\u8c61\u7c7b\u578b\u3002\u4e00\u79cd\u65b9\u6cd5\u662f\u8fc7\u6ee4 \u4f7f\u7528\u00a0Type\u00a0\u9650\u5b9a\u7b26\u7684\u7ed3\u679c\u3002\u6b64\u793a\u4f8b\u67e5\u8be2\u4e8b\u4ef6 \u901a\u8fc7\u201c\u4ec0\u4e48\u201d\u4e0e\u201c\u5e10\u6237\u201d\u6216\u201c\u5546\u673a\u201d\u76f8\u5173 \u7530\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Event&gt; events = &#91;SELECT Description FROM Event WHERE What.Type IN ('Account', 'Opportunity')];<\/code><\/pre>\n\n\n\n<p>\u53e6\u4e00\u4e2a \u65b9\u6cd5\u662f\u5728 SOQL \u8bed\u53e5\u3002\u6b64\u793a\u4f8b\u8fd8\u67e5\u8be2 \u901a\u8fc7\u201c\u4ec0\u4e48\u201d\u4e0e\u201c\u5ba2\u6237\u201d\u6216\u201c\u5546\u673a\u201d\u76f8\u5173\u7684\u4e8b\u4ef6 \u7530\u3002<\/p>\n\n\n\n<p><samp>TYPEOF<\/samp><samp>SELECT<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>List&lt;Event&gt; events = &#91;SELECT TYPEOF What WHEN Account THEN Phone WHEN Opportunity THEN Amount END FROM Event];<\/code><\/pre>\n\n\n\n<p>\u8fd9\u4e9b \u67e5\u8be2\u8fd4\u56de sObject \u5217\u8868\uff0c\u5176\u4e2d\u5173\u7cfb\u5b57\u6bb5\u5f15\u7528\u6240\u9700\u7684 \u5bf9\u8c61\u7c7b\u578b\u3002\u5982\u679c\u9700\u8981\u8bbf\u95ee\u591a\u6001\u5173\u7cfb\u4e2d\u7684\u5f15\u7528\u5bf9\u8c61\uff0c\u53ef\u4ee5\u4f7f\u7528\u00a0instanceof\u00a0\u5173\u952e\u5b57\u8bbe\u7f6e\u4e3a \u786e\u5b9a\u5bf9\u8c61\u7c7b\u578b\u3002\u4ee5\u4e0b\u793a\u4f8b\u7528\u4e8e\u786e\u5b9a Account \u6216 Opportunity \u662f\u5426\u4e0e \u4e8b\u4ef6\u3002<\/p>\n\n\n\n<p><samp>instanceof<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Event myEvent = eventFromQuery;\nif (myEvent.What instanceof Account) {\n    \/\/ myEvent.What references an Account, so process accordingly\n} else if (myEvent.What instanceof Opportunity) {\n    \/\/ myEvent.What references an Opportunity, so process accordingly\n}<\/code><\/pre>\n\n\n\n<p>\u8bf7\u6ce8\u610f\uff0c\u5fc5\u987b\u5206\u914d\u67e5\u8be2\u8fd4\u56de\u5230\u7684\u5f15\u7528\u7684 sObject \u4e00\u4e2a\u9002\u5f53\u7c7b\u578b\u7684\u53d8\u91cf\uff0c\u7136\u540e\u624d\u80fd\u5c06\u5176\u4f20\u9012\u7ed9\u53e6\u4e00\u4e2a\u65b9\u6cd5\u3002\u8fd9 \u4ee5\u4e0b\u793a\u4f8b<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f7f\u7528 SOQL \u67e5\u8be2Merchandise__c\u81ea\u5b9a\u4e49\u5bf9\u8c61\u7684\u7528\u6237\u6216\u7ec4\u6240\u6709\u8005 \u4f7f\u7528\u5b50\u53e5\u8fdb\u884c\u67e5\u8be2<samp>TYPEOF<\/samp><\/li>\n\n\n\n<li>\u7528\u4e8e\u786e\u5b9a\u6240\u6709\u8005 \u7c7b\u578b<samp>instanceof<\/samp><\/li>\n\n\n\n<li>\u5c06\u6240\u6709\u8005\u5bf9\u8c61\u5206\u914d\u7ed9\u7528\u6237\u6216\u7ec4\u7c7b\u578b\u53d8\u91cf\uff0c\u7136\u540e\u518d\u5c06\u5176\u4f20\u9012\u7ed9 \u5b9e\u7528\u7a0b\u5e8f\u65b9\u6cd5<\/li>\n<\/ol>\n\n\n\n<pre class=\"wp-block-code\"><code>public class PolymorphismExampleClass {\n\n    \/\/ Utility method for a User\n    public static void processUser(User theUser) {\n        System.debug('Processed User');\n    }\n    \n    \/\/ Utility method for a Group\n    public static void processGroup(Group theGroup) {\n        System.debug('Processed Group');\n    }\n\n    public static void processOwnersOfMerchandise() {\n        \/\/ Select records based on the Owner polymorphic relationship field\n        List&lt;Merchandise__c&gt; merchandiseList = &#91;SELECT TYPEOF Owner WHEN User THEN LastName WHEN Group THEN Email END FROM Merchandise__c];\t\n        \/\/ We now have a list of Merchandise__c records owned by either a User or Group\n        for (Merchandise__c merch: merchandiseList) {\n            \/\/ We can use instanceof to check the polymorphic relationship type\n            \/\/ Note that we have to assign the polymorphic reference to the appropriate\n            \/\/ sObject type before passing to a method\n            if (merch.Owner instanceof User) {\n                User userOwner = merch.Owner;\n                processUser(userOwner);\n            } else if (merch.Owner instanceof Group) {\n                Group groupOwner = merch.Owner;\n                processGroup(groupOwner);\n            }\n        }\n    }\n}\n<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u5728 SOQL \u548c SOSL \u67e5\u8be2\u4e2d\u4f7f\u7528 Apex \u53d8\u91cf<\/h1>\n\n\n\n<p><a><\/a>Apex \u4e2d\u7684 SOQL \u548c SOSL \u8bed\u53e5\u53ef\u4ee5\u5f15\u7528 Apex \u4ee3\u7801 \u53d8\u91cf\u548c\u8868\u8fbe\u5f0f\uff08\u5982\u679c\u5b83\u4eec\u524d\u9762\u6709\u5192\u53f7 \uff08\uff09\u3002\u5728 SOQL \u4e2d\u4f7f\u7528\u5c40\u90e8\u4ee3\u7801\u53d8\u91cf \u6216 SOSL \u8bed\u53e5\u79f0\u4e3a<dfn>\u7ed1\u5b9a<\/dfn>\u3002Apex \u89e3\u6790\u5668\u9996\u5148\u8bc4\u4f30 \u6267\u884c SOQL \u6216 SOSL \u8bed\u53e5\u4e4b\u524d\u4ee3\u7801\u4e0a\u4e0b\u6587\u4e2d\u7684\u5c40\u90e8\u53d8\u91cf\u3002<samp>:<\/samp>\u6346 \u8868\u8fbe\u5f0f\u53ef\u4ee5\u7528\u4f5c\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b50\u53e5\u4e2d\u7684\u641c\u7d22\u5b57\u7b26\u4e32\u3002<samp>FIND<\/samp><\/li>\n\n\n\n<li>\u5b50\u53e5\u4e2d\u7684\u7b5b\u9009\u5668\u6587\u672c\u3002<samp>WHERE<\/samp><\/li>\n\n\n\n<li>\u5b50\u53e5\u4e2d or \u8fd0\u7b97\u7b26\u7684\u503c\uff0c\u5141\u8bb8\u5bf9\u4e00\u7ec4\u52a8\u6001\u503c\u8fdb\u884c\u7b5b\u9009\u3002\u8bf7\u6ce8\u610f\uff0c \u8fd9\u5bf9\u4e8e ID \u6216\u5b57\u7b26\u4e32\u5217\u8868\u7279\u522b\u6709\u7528\uff0c\u5c3d\u7ba1\u5b83\u9002\u7528\u4e8e \u4efb\u4f55\u7c7b\u578b\u3002<samp>IN<\/samp><samp>NOT IN<\/samp><samp>WHERE<\/samp><\/li>\n\n\n\n<li>\u5b50\u53e5\u4e2d\u7684\u5206\u90e8\u540d\u79f0\u3002<samp>WITH DIVISION<\/samp><\/li>\n\n\n\n<li>\u5b50\u53e5\u4e2d\u7684\u6570\u503c\u3002<samp>LIMIT<\/samp><\/li>\n\n\n\n<li>\u5b50\u53e5\u4e2d\u7684\u6570\u503c\u3002<samp>OFFSET<\/samp><\/li>\n<\/ul>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Account A = new Account(Name='xxx');\ninsert A;\nAccount B;\n\n\/\/ A simple bind\nB = &#91;SELECT Id FROM Account WHERE Id = :A.Id];\n\n\/\/ A bind with arithmetic\nB = &#91;SELECT Id FROM Account \n     WHERE Name = :('x' + 'xx')];\n\nString s = 'XXX';\n\n\/\/ A bind with expressions\nB = &#91;SELECT Id FROM Account \n     WHERE Name = :'XXXX'.substring(0,3)];\n\n\/\/ A bind with INCLUDES clause\nB = &#91;SELECT Id FROM Account WHERE :A.TYPE INCLUDES (\u2018Customer \u2013 Direct; Customer \u2013 Channel\u2019)];\n\n\/\/ A bind with an expression that is itself a query result\nB = &#91;SELECT Id FROM Account\n     WHERE Name = :&#91;SELECT Name FROM Account\n                    WHERE Id = :A.Id].Name];\n\nContact C = new Contact(LastName='xxx', AccountId=A.Id);\ninsert new Contact&#91;]{C, new Contact(LastName='yyy', \n                                    accountId=A.id)};\n\n\/\/ Binds in both the parent and aggregate queries\nB = &#91;SELECT Id, (SELECT Id FROM Contacts\n                 WHERE Id = :C.Id)\n     FROM Account\n     WHERE Id = :A.Id];\n\n\/\/ One contact returned\nContact D = B.Contacts;\n\n\/\/ A limit bind\nInteger i = 1;\nB = &#91;SELECT Id FROM Account LIMIT :i];\n\n\/\/ An OFFSET bind\nInteger offsetVal = 10;\nList&lt;Account&gt; offsetList = &#91;SELECT Id FROM Account OFFSET :offsetVal];\n\n\/\/ An IN-bind with an Id list. Note that a list of sObjects\n\/\/ can also be used--the Ids of the objects are used for \n\/\/ the bind\nContact&#91;] cc = &#91;SELECT Id FROM Contact LIMIT 2];\nTask&#91;] tt = &#91;SELECT Id FROM Task WHERE WhoId IN :cc];\n\n\/\/ An IN-bind with a String list\nString&#91;] ss = new String&#91;]{'a', 'b'};\nAccount&#91;] aa = &#91;SELECT Id FROM Account \n                WHERE AccountNumber IN :ss];\n\n\/\/ A SOSL query with binds in all possible clauses\n\nString myString1 = 'aaa';\nString myString2 = 'bbb';\nInteger myInt3 = 11;\nString myString4 = 'ccc';\nInteger myInt5 = 22;\n\nList&lt;List&lt;SObject&gt;&gt; searchList = &#91;FIND :myString1 IN ALL FIELDS \n                                  RETURNING \n                                     Account (Id, Name WHERE Name LIKE :myString2\n                                              LIMIT :myInt3), \n                                     Contact, \n                                     Opportunity, \n                                     Lead \n                                  WITH DIVISION =:myString4 \n                                  LIMIT :myInt5];<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f\u5355\u4f4d\u4e0d\u652f\u6301 Apex \u7ed1\u5b9a\u53d8\u91cf \u53c2\u6570\u3002\u6b64\u67e5\u8be2 \u4e0d\u8d77\u4f5c\u7528\u3002<\/p>\n\n\n\n<p><samp>DISTANCE<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String units = 'mi';\nList&lt;Account&gt; accountList = \n    &#91;SELECT ID, Name, BillingLatitude, BillingLongitude \n     FROM Account \n     WHERE DISTANCE(My_Location_Field__c, GEOLOCATION(10,10), :units) &lt; 10];<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528 SOQL \u8bed\u53e5\u67e5\u8be2\u6240\u6709\u8bb0\u5f55<\/h1>\n\n\n\n<p>SOQL \u8bed\u53e5\u53ef\u4ee5\u4f7f\u7528\u5173\u952e\u5b57\u67e5\u8be2\u7ec4\u7ec7\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\uff0c\u5305\u62ec \u5df2\u5220\u9664\u7684\u8bb0\u5f55\u548c\u5b58\u6863\u7684\u6d3b\u52a8\u3002\u4f8b\u5982\uff1a<\/p>\n\n\n\n<p><samp>ALL ROWS<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>System.assertEquals(2, &#91;SELECT COUNT() FROM Contact WHERE AccountId = a.Id ALL ROWS]);<\/code><\/pre>\n\n\n\n<p>\u60a8\u53ef\u4ee5\u4f7f\u7528 \u7ec4\u7ec7\u7684\u56de\u6536\u7ad9\u3002\u4e0d\u80fd\u5c06\u5173\u952e\u5b57\u4e0e\u5173\u952e\u5b57\u4e00\u8d77\u4f7f\u7528\u3002<samp>ALL ROWS<\/samp><samp>ALL ROWS<\/samp><samp>FOR UPDATE<\/samp><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">SOQL For \u5faa\u73af<\/h1>\n\n\n\n<p>SOQL \u5faa\u73af\u904d\u5386\u6240\u6709 SOQL \u67e5\u8be2\u8fd4\u56de\u7684 sObject \u8bb0\u5f55\u3002<\/p>\n\n\n\n<p><samp>for<\/samp>SOQL \u5faa\u73af\u7684\u8bed\u6cd5\u662f \u4e5f\uff1a<\/p>\n\n\n\n<p><samp>for<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (<em>variable<\/em> : &#91;<em>soql_query<\/em>]) {\n    <em>code_block<\/em>\n}<\/code><\/pre>\n\n\n\n<p>\u6216<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (<em>variable_list<\/em> : &#91;<em>soql_query<\/em>]) {\n    <em>code_block<\/em>\n}<\/code><\/pre>\n\n\n\n<p>\u4e24\u8005 \u548c \u5fc5\u987b\u4e0e sObject \u7684\u7c7b\u578b\u76f8\u540c \u7531 \u8fd4\u56de\u3002\u4e0e\u6807\u51c6 SOQL \u67e5\u8be2\u4e00\u6837\uff0c\u8be5\u8bed\u53e5\u53ef\u4ee5\u5f15\u7528 \u5728\u5176\u5b50\u53e5\u4e2d\u5bf9\u8868\u8fbe\u5f0f\u8fdb\u884c\u7f16\u7801 \u4f7f\u7528\u8bed\u6cd5\u3002\u4e3a \u4f8b\uff1a<\/p>\n\n\n\n<p><samp>&nbsp;<var>variable<\/var><\/samp><samp>&nbsp;<var>variable_list<\/var><\/samp><samp>&nbsp;<var>soql_query<\/var><\/samp><samp>[<var>soql_query<\/var>]<\/samp><samp>WHERE<\/samp><samp>:<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String s = 'Acme';\nfor (Account a : &#91;SELECT Id, Name from Account\n                  where Name LIKE :(s+'%')]) {\n    \/\/ Your code\n}<\/code><\/pre>\n\n\n\n<p>\u4e0b\u9762\u7684\u793a\u4f8b\u5c06 SOQL \u67e5\u8be2\u521b\u5efa\u5217\u8868\u4e0e DML \u65b9\u6cd5\u76f8\u7ed3\u5408\u3002<\/p>\n\n\n\n<p><samp>update<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Create a list of account records from a SOQL query\nList&lt;Account&gt; accs = &#91;SELECT Id, Name FROM Account WHERE Name = 'Siebel']; \n\n\/\/ Loop through the list and update the Name field\nfor(Account a : accs){\n   a.Name = 'Oracle';\n}\n\n\/\/ Update the database\nupdate accs;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">SOQL For \u5faa\u73af\u4e0e\u6807\u51c6 SOQL \u67e5\u8be2<\/h2>\n\n\n\n<p>SOQL \u5faa\u73af\u4e0d\u540c\u4e8e\u6807\u51c6 SOQL \u8bed\u53e5\uff0c\u56e0\u4e3a\u5b83\u4eec\u7528\u4e8e\u68c0\u7d22 sObject \u7684\u65b9\u6cd5\u3002\u867d\u7136\u6807\u51c6\u00a0SOQL \u548c SOSL\u00a0\u67e5\u8be2\u4e2d\u8ba8\u8bba\u7684\u67e5\u8be2\u53ef\u4ee5\u68c0\u7d22\u67e5\u8be2\u6216\u591a\u4e2a\u5bf9\u8c61\u8bb0\u5f55\uff0c SOQL \u5faa\u73af\u68c0\u7d22\u6240\u6709 sObject\uff0c\u4f7f\u7528 \u901a\u8fc7\u8c03\u7528 SOAP API \u7684 \u548c \u65b9\u6cd5\u8fdb\u884c\u9ad8\u6548\u5206\u5757\u3002 \u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528 SOQL \u5faa\u73af\u6765\u5904\u7406\u8fd4\u56de\u7684\u67e5\u8be2\u7ed3\u679c\uff0c\u4ece\u800c\u907f\u514d\u5bf9\u5806\u5927\u5c0f\u7684\u9650\u5236 \u591a\u6761\u8bb0\u5f55\u3002\u4f46\u662f\uff0c\u6b64\u65b9\u6cd5\u53ef\u80fd\u4f1a\u5bfc\u81f4\u4f7f\u7528\u66f4\u591a\u7684 CPU \u5468\u671f\u3002 \u8bf7\u53c2\u89c1\u5806\u603b\u5927\u5c0f\u3002<samp>forcountforqueryqueryMorefor<\/samp><\/p>\n\n\n\n<p>\u5305\u542b\u805a\u5408\u51fd\u6570\u7684\u67e5\u8be2\u4e0d\u652f\u6301 \u3002\u5982\u679c\u51fa\u73b0\u4ee5\u4e0b\u60c5\u51b5\uff0c\u5219\u4f1a\u53d1\u751f\u8fd0\u884c\u65f6\u5f02\u5e38 \u4f7f\u7528\u5305\u542b\u805a\u5408\u51fd\u6570\u7684\u67e5\u8be2\uff0c\u8be5\u805a\u5408\u51fd\u6570\u5728\u5faa\u73af\u4e2d\u8fd4\u56de\u8d85\u8fc7 2,000 \u884c\u3002<samp>queryMorefor<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SOQL For \u5faa\u73af\u683c\u5f0f<\/h2>\n\n\n\n<p>SOQL \u5faa\u73af\u53ef\u4ee5\u4e00\u6b21\u5904\u7406\u4e00\u4e2a\u8bb0\u5f55 \u65f6\u95f4\u4f7f\u7528\u5355\u4e2a sObject \u53d8\u91cf\uff0c\u6216\u4e00\u6b21\u4f7f\u7528 sObject \u5217\u8868\uff1a<\/p>\n\n\n\n<p><samp>for<\/samp><a><\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\" id=\"ForLoopSingleVersusList\">\n<li>\u5355\u4e2a sObject \u683c\u5f0f\u5bf9\u6bcf\u4e2a sObject \u8bb0\u5f55\u6267\u884c\u4e00\u6b21\u5faa\u73af\u3002\u56e0\u6b64 \u5b83\u6613\u4e8e\u7406\u89e3\u548c\u4f7f\u7528\uff0c\u4f46\u5982\u679c\u60a8\u613f\u610f\uff0c\u6548\u7387\u975e\u5e38\u4f4e\u4e0b \u5728\u5faa\u73af\u4f53\u4e2d\u4f7f\u7528\u6570\u636e\u64cd\u4f5c\u8bed\u8a00 \uff08DML\uff09 \u8bed\u53e5\u3002\u6bcf\u4e2a DML \u8bed\u53e5\u7ed3\u675f \u4e00\u6b21\u53ea\u80fd\u5904\u7406\u4e00\u4e2a sObject\u3002<samp>for<\/samp><samp>&lt;code_block&gt;<\/samp><samp>for<\/samp><\/li>\n\n\n\n<li>sObject \u5217\u8868\u683c\u5f0f\u5bf9\u6bcf\u4e2a\u5305\u542b 200 \u4e2a sObject \u7684\u5217\u8868\u6267\u884c\u4e00\u6b21\u5faa\u73af\u3002 \u56e0\u6b64\uff0c\u5b83\u66f4\u96be\u7406\u89e3\u548c\u4f7f\u7528\uff0c\u4f46 \u5982\u679c\u5fc5\u987b\u5728\u5faa\u73af\u4f53\u4e2d\u4f7f\u7528 DML \u8bed\u53e5\uff0c\u5219\u4e3a\u6700\u4f73\u9009\u62e9\u3002\u6bcf\u4e2a DML \u8bed\u53e5\u53ef\u4ee5 \u4e00\u6b21\u6279\u91cf\u5904\u7406 sObject \u5217\u8868\u3002<samp>for<\/samp><samp>&lt;code_block&gt;<\/samp><samp>for<\/samp><\/li>\n<\/ul>\n\n\n\n<p>For example, the following code illustrates the difference between the two types of SOQL query&nbsp;loops:&nbsp;<\/p>\n\n\n\n<p><samp>for<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Create a savepoint because the data should not be committed to the database\nSavepoint sp = Database.setSavepoint(); \n\ninsert new Account&#91;]{new Account(Name = 'yyy'), \n                     new Account(Name = 'yyy'), \n                     new Account(Name = 'yyy')};\n\n\/\/ The single sObject format executes the for loop once per returned record\nInteger i = 0;\nfor (Account tmp : &#91;SELECT Id FROM Account WHERE Name = 'yyy']) {\n    i++;\n}\nSystem.assert(i == 3); \/\/ Since there were three accounts named 'yyy' in the\n                       \/\/ database, the loop executed three times\n\n\/\/ The sObject list format executes the for loop once per returned batch\n\/\/ of records\ni = 0;\nInteger j;\nfor (Account&#91;] tmp : &#91;SELECT Id FROM Account WHERE Name = 'yyy']) {\n    j = tmp.size();\n    i++;\n}\nSystem.assert(j == 3); \/\/ The lt should have contained the three accounts\n                       \/\/ named 'yyy'\nSystem.assert(i == 1); \/\/ Since a single batch can hold up to 200 records and,\n                       \/\/ only three records should have been returned, the \n                       \/\/ loop should have executed only once\n\n\/\/ Revert the database to the original state\nDatabase.rollback(sp);<\/code><\/pre>\n\n\n\n<p>\u6ce8\u610f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u548c\u5173\u952e\u5b57\u53ef\u7528\u4e8e\u4e24\u8005 \u5185\u8054\u67e5\u8be2\u5faa\u73af\u7684\u7c7b\u578b \u683c\u5f0f\u3002\u4f7f\u7528 sObject \u5217\u8868\u683c\u5f0f\u65f6\uff0c\u8df3\u5230\u4e0b\u4e00\u4e2a sObject \u5217\u8868\u3002<samp>break<\/samp><samp>continue<\/samp><samp>for<\/samp><samp>continue<\/samp><\/li>\n\n\n\n<li>DML \u8bed\u53e5\u4e00\u6b21\u6700\u591a\u53ea\u80fd\u5904\u7406 10,000 \u6761\u8bb0\u5f55\uff0c\u800c sObject \u5217\u51fa\u5faa\u73af\u8fdb\u7a0b\u8bb0\u5f55 \u6bcf\u6279 200 \u4e2a\u3002\u56e0\u6b64\uff0c\u5982\u679c\u60a8\u8981\u63d2\u5165\u3001\u66f4\u65b0\u6216\u5220\u9664 \u5728 sObject \u5217\u8868\u5faa\u73af\u4e2d\uff0c\u6bcf\u4e2a\u8fd4\u56de\u7684\u8bb0\u5f55\u90fd\u6709\u591a\u4e2a\u8bb0\u5f55\uff0c\u53ef\u80fd\u4f1a\u9047\u5230 \u8fd0\u884c\u65f6\u9650\u5236\u7684\u9519\u8bef\u3002\u67e5\u770b\u6267\u884c \u8c03\u901f\u5668\u548c\u9650\u5236\u3002<samp>for<\/samp><samp>for<\/samp><\/li>\n\n\n\n<li>\u4f60\u53ef\u80fd\u4f1a\u5f97\u5230\u4e00\u4e2a \u5e26\u6709\u6d88\u606f \u7684 SOQL \u5faa\u73af\u3002\u6709\u65f6\u4f1a\u5f15\u53d1\u6b64\u5f02\u5e38 \u5f53\u8bbf\u95ee\u68c0\u7d22\u5230\u7684\u5927\u91cf\u5b50\u8bb0\u5f55\uff08200 \u4e2a\u6216\u66f4\u591a\uff09\u65f6 sObject\uff0c\u6216\u8005\u5728\u83b7\u53d6\u6b64\u7c7b\u8bb0\u5f55\u96c6\u7684\u5927\u5c0f\u65f6\u3002\u4e3a \u4f8b\u5982\uff0c\u4ee5\u4e0b SOQL \u5faa\u73af\u4e2d\u7684\u67e5\u8be2\u68c0\u7d22\u7279\u5b9a\u5e10\u6237\u7684\u5b50\u8054\u7cfb\u4eba\u3002\u5982\u679c \u6b64\u5e10\u6237\u5305\u542b 200 \u591a\u4e2a\u5b50\u8054\u7cfb\u4eba\uff0c\u5faa\u73af\u4e2d\u7684\u8bed\u53e5\u4f1a\u5bfc\u81f4\u5f02\u5e38\u3002<samp>QueryException<\/samp><samp>for<\/samp><samp>Aggregate query has too many rows for direct assignment, use FOR loop<\/samp><samp>for<\/samp><samp>for<\/samp><code>for (Account acct : [SELECT Id, Name, (SELECT Id, Name FROM Contacts) FROM Account WHERE Id IN ('&lt;ID value&gt;')]) { List&lt;Contact&gt; contactList = acct.Contacts; \/\/ Causes an error Integer count = acct.Contacts.size(); \/\/ Causes an error }<\/code><\/li>\n<\/ul>\n\n\n\n<p>\u82e5\u8981\u907f\u514d\u51fa\u73b0\u6b64\u5f02\u5e38\uff0c\u8bf7\u4f7f\u7528\u5faa\u73af\u904d\u5386\u5b50\u9879 \u8bb0\u5f55\uff0c\u4f5c\u4e3a \u9075\u5faa\u3002<\/p>\n\n\n\n<p><samp>for<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>for (Account acct : &#91;SELECT Id, Name, (SELECT Id, Name FROM Contacts) \n                    FROM Account WHERE Id IN ('&lt;ID value&gt;')]) { \n    Integer count=0;\n    for (Contact c : acct.Contacts) {\n        count++;\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u60a8\u53ef\u4ee5\u8bc4\u4f30 Salesforce \u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00 \uff08SOQL\uff09 \u6216 Salesforce \u5bf9\u8c61\u641c\u7d22 \u8bed\u8a00 \uff08SOSL\uff09 \u8bed\u53e5\u5728 Apex \u4e2d\u52a8\u6001\uff0c\u65b9\u6cd5\u662f\u5c06\u8bed\u53e5\u62ec\u5728\u6b63\u65b9\u5f62\u4e2d \u62ec\u5f27\u3002<\/p>\n","protected":false},"author":1,"featured_media":3658,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[199],"tags":[],"class_list":["post-3657","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apex-"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>SOQL \u548c SOSL \u67e5\u8be2 - \u767d\u767d\u968f\u7b14<\/title>\n<meta name=\"description\" content=\"\u60a8\u53ef\u4ee5\u8bc4\u4f30 Salesforce \u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00 \uff08SOQL\uff09 \u6216 Salesforce \u5bf9\u8c61\u641c\u7d22 \u8bed\u8a00 \uff08SOSL\uff09 \u8bed\u53e5\u5728 Apex \u4e2d\u52a8\u6001\uff0c\u65b9\u6cd5\u662f\u5c06\u8bed\u53e5\u62ec\u5728\u6b63\u65b9\u5f62\u4e2d \u62ec\u5f27\u3002SOQL \u8bed\u53e5SOQL \u8bed\u53e5\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a\u65b9\u6cd5\u67e5\u8be2\u7684 sObjects\u3001\u5355\u4e2a sObject \u6216 Integer \u5217\u8868\u3002\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"http:\/\/www.ponybai.com\/?p=3657\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SOQL \u548c SOSL \u67e5\u8be2 - \u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"og:description\" content=\"\u60a8\u53ef\u4ee5\u8bc4\u4f30 Salesforce \u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00 \uff08SOQL\uff09 \u6216 Salesforce \u5bf9\u8c61\u641c\u7d22 \u8bed\u8a00 \uff08SOSL\uff09 \u8bed\u53e5\u5728 Apex \u4e2d\u52a8\u6001\uff0c\u65b9\u6cd5\u662f\u5c06\u8bed\u53e5\u62ec\u5728\u6b63\u65b9\u5f62\u4e2d \u62ec\u5f27\u3002SOQL \u8bed\u53e5SOQL \u8bed\u53e5\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a\u65b9\u6cd5\u67e5\u8be2\u7684 sObjects\u3001\u5355\u4e2a sObject \u6216 Integer \u5217\u8868\u3002\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.ponybai.com\/?p=3657\" \/>\n<meta property=\"og:site_name\" content=\"\u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"article:published_time\" content=\"2023-11-27T09:53:33+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-21T10:04:38+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/11\/soql-sosl.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1123\" \/>\n\t<meta property=\"og:image:height\" content=\"222\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"ponybai\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"ponybai\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"6 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3657#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3657\"},\"author\":{\"name\":\"ponybai\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"headline\":\"SOQL \u548c SOSL \u67e5\u8be2\",\"datePublished\":\"2023-11-27T09:53:33+00:00\",\"dateModified\":\"2023-11-21T10:04:38+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3657\"},\"wordCount\":464,\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"articleSection\":[\"Apex \u5f00\u53d1\u4eba\u5458\u6307\u5357\"],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3657\",\"url\":\"http:\/\/www.ponybai.com\/?p=3657\",\"name\":\"SOQL \u548c SOSL \u67e5\u8be2 - \u767d\u767d\u968f\u7b14\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/#website\"},\"datePublished\":\"2023-11-27T09:53:33+00:00\",\"dateModified\":\"2023-11-21T10:04:38+00:00\",\"description\":\"\u60a8\u53ef\u4ee5\u8bc4\u4f30 Salesforce \u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00 \uff08SOQL\uff09 \u6216 Salesforce \u5bf9\u8c61\u641c\u7d22 \u8bed\u8a00 \uff08SOSL\uff09 \u8bed\u53e5\u5728 Apex \u4e2d\u52a8\u6001\uff0c\u65b9\u6cd5\u662f\u5c06\u8bed\u53e5\u62ec\u5728\u6b63\u65b9\u5f62\u4e2d \u62ec\u5f27\u3002SOQL \u8bed\u53e5SOQL \u8bed\u53e5\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a\u65b9\u6cd5\u67e5\u8be2\u7684 sObjects\u3001\u5355\u4e2a sObject \u6216 Integer \u5217\u8868\u3002\",\"breadcrumb\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3657#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.ponybai.com\/?p=3657\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3657#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/www.ponybai.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SOQL \u548c SOSL \u67e5\u8be2\"}]},{\"@type\":\"WebSite\",\"@id\":\"http:\/\/www.ponybai.com\/#website\",\"url\":\"http:\/\/www.ponybai.com\/\",\"name\":\"\u767d\u767d\u968f\u7b14\",\"description\":\"Salesforce\u5b98\u65b9\u8bb2\u5e08\",\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"http:\/\/www.ponybai.com\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\",\"name\":\"ponybai\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg\",\"contentUrl\":\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg\",\"width\":248,\"height\":248,\"caption\":\"ponybai\"},\"logo\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/121.37.188.161\"],\"url\":\"http:\/\/www.ponybai.com\/?author=1\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"SOQL \u548c SOSL \u67e5\u8be2 - \u767d\u767d\u968f\u7b14","description":"\u60a8\u53ef\u4ee5\u8bc4\u4f30 Salesforce \u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00 \uff08SOQL\uff09 \u6216 Salesforce \u5bf9\u8c61\u641c\u7d22 \u8bed\u8a00 \uff08SOSL\uff09 \u8bed\u53e5\u5728 Apex \u4e2d\u52a8\u6001\uff0c\u65b9\u6cd5\u662f\u5c06\u8bed\u53e5\u62ec\u5728\u6b63\u65b9\u5f62\u4e2d \u62ec\u5f27\u3002SOQL \u8bed\u53e5SOQL \u8bed\u53e5\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a\u65b9\u6cd5\u67e5\u8be2\u7684 sObjects\u3001\u5355\u4e2a sObject \u6216 Integer \u5217\u8868\u3002","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"http:\/\/www.ponybai.com\/?p=3657","og_locale":"zh_CN","og_type":"article","og_title":"SOQL \u548c SOSL \u67e5\u8be2 - \u767d\u767d\u968f\u7b14","og_description":"\u60a8\u53ef\u4ee5\u8bc4\u4f30 Salesforce \u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00 \uff08SOQL\uff09 \u6216 Salesforce \u5bf9\u8c61\u641c\u7d22 \u8bed\u8a00 \uff08SOSL\uff09 \u8bed\u53e5\u5728 Apex \u4e2d\u52a8\u6001\uff0c\u65b9\u6cd5\u662f\u5c06\u8bed\u53e5\u62ec\u5728\u6b63\u65b9\u5f62\u4e2d \u62ec\u5f27\u3002SOQL \u8bed\u53e5SOQL \u8bed\u53e5\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a\u65b9\u6cd5\u67e5\u8be2\u7684 sObjects\u3001\u5355\u4e2a sObject \u6216 Integer \u5217\u8868\u3002","og_url":"http:\/\/www.ponybai.com\/?p=3657","og_site_name":"\u767d\u767d\u968f\u7b14","article_published_time":"2023-11-27T09:53:33+00:00","article_modified_time":"2023-11-21T10:04:38+00:00","og_image":[{"width":1123,"height":222,"url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/11\/soql-sosl.png","type":"image\/png"}],"author":"ponybai","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"ponybai","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"6 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.ponybai.com\/?p=3657#article","isPartOf":{"@id":"http:\/\/www.ponybai.com\/?p=3657"},"author":{"name":"ponybai","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"headline":"SOQL \u548c SOSL \u67e5\u8be2","datePublished":"2023-11-27T09:53:33+00:00","dateModified":"2023-11-21T10:04:38+00:00","mainEntityOfPage":{"@id":"http:\/\/www.ponybai.com\/?p=3657"},"wordCount":464,"publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"articleSection":["Apex \u5f00\u53d1\u4eba\u5458\u6307\u5357"],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/www.ponybai.com\/?p=3657","url":"http:\/\/www.ponybai.com\/?p=3657","name":"SOQL \u548c SOSL \u67e5\u8be2 - \u767d\u767d\u968f\u7b14","isPartOf":{"@id":"http:\/\/www.ponybai.com\/#website"},"datePublished":"2023-11-27T09:53:33+00:00","dateModified":"2023-11-21T10:04:38+00:00","description":"\u60a8\u53ef\u4ee5\u8bc4\u4f30 Salesforce \u5bf9\u8c61\u67e5\u8be2\u8bed\u8a00 \uff08SOQL\uff09 \u6216 Salesforce \u5bf9\u8c61\u641c\u7d22 \u8bed\u8a00 \uff08SOSL\uff09 \u8bed\u53e5\u5728 Apex \u4e2d\u52a8\u6001\uff0c\u65b9\u6cd5\u662f\u5c06\u8bed\u53e5\u62ec\u5728\u6b63\u65b9\u5f62\u4e2d \u62ec\u5f27\u3002SOQL \u8bed\u53e5SOQL \u8bed\u53e5\u7684\u8ba1\u7b97\u7ed3\u679c\u4e3a\u65b9\u6cd5\u67e5\u8be2\u7684 sObjects\u3001\u5355\u4e2a sObject \u6216 Integer \u5217\u8868\u3002","breadcrumb":{"@id":"http:\/\/www.ponybai.com\/?p=3657#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.ponybai.com\/?p=3657"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.ponybai.com\/?p=3657#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/www.ponybai.com\/"},{"@type":"ListItem","position":2,"name":"SOQL \u548c SOSL \u67e5\u8be2"}]},{"@type":"WebSite","@id":"http:\/\/www.ponybai.com\/#website","url":"http:\/\/www.ponybai.com\/","name":"\u767d\u767d\u968f\u7b14","description":"Salesforce\u5b98\u65b9\u8bb2\u5e08","publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"http:\/\/www.ponybai.com\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":["Person","Organization"],"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883","name":"ponybai","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/","url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg","contentUrl":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2025\/03\/cropped-Ihsans-WeChatQR.jpg","width":248,"height":248,"caption":"ponybai"},"logo":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/121.37.188.161"],"url":"http:\/\/www.ponybai.com\/?author=1"}]}},"_links":{"self":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3657","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3657"}],"version-history":[{"count":1,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3657\/revisions"}],"predecessor-version":[{"id":3659,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3657\/revisions\/3659"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/media\/3658"}],"wp:attachment":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3657"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3657"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3657"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}