{"id":3872,"date":"2024-01-17T16:29:17","date_gmt":"2024-01-17T08:29:17","guid":{"rendered":"http:\/\/www.ponybai.com\/?p=3872"},"modified":"2023-12-02T16:58:00","modified_gmt":"2023-12-02T08:58:00","slug":"%e8%b0%83%e7%94%a8-apex-%e6%96%b9%e6%b3%95","status":"publish","type":"post","link":"http:\/\/www.ponybai.com\/?p=3872","title":{"rendered":"\u8c03\u7528 Apex \u65b9\u6cd5"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Lightning Web \u7ec4\u4ef6\u53ef\u4ee5\u4ece Apex \u7c7b\u5bfc\u5165\u65b9\u6cd5\u3002\u5bfc\u5165\u7684\u65b9\u6cd5\u662f\u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u8c03\u7528\u7684\u51fd\u6570\u3002<code>@wire<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528\u57fa\u672c Lightning \u7ec4\u4ef6\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u91cd\u8981<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5047\u8bbe Apex \u65b9\u6cd5\u63d0\u4f9b\u4e0d\u53ef\u53d8\u6570\u636e\uff0c\u5373\u4f7f\u4eca\u5929\u53ef\u4ee5\u6539\u53d8\u6570\u636e\u3002\u6700\u4f73\u505a\u6cd5\u662f\u5c06\u7ec4\u4ef6\u63a5\u6536\u7684\u6240\u6709\u6570\u636e\u89c6\u4e3a\u4e0d\u53ef\u53d8\u6570\u636e\u3002\u82e5\u8981\u66f4\u6539\u6570\u636e\uff0c\u8bf7\u521b\u5efa\u8981\u66f4\u6539\u7684\u5bf9\u8c61\u7684\u6d45\u62f7\u8d1d\u3002\u5728\u5904\u7406\u6570\u636e\u65f6\uff0c\u4e86\u89e3\u8fd9\u4e2a\u6982\u5ff5\u975e\u5e38\u91cd\u8981\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6d41\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f8b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">lwc-recipes\u00a0\u5b58\u50a8\u5e93\u5177\u6709\u591a\u4e2a\u8c03\u7528 Apex \u65b9\u6cd5\u7684\u7ec4\u4ef6\u3002\u67e5\u627e\u540d\u79f0\u4ee5 \u5f00\u5934\u7684\u7ec4\u4ef6\u3002<code>apex<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Apex\u9650\u5236<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6bcf\u6b21\u8c03\u7528 Apex \u65b9\u6cd5\u65f6\u90fd\u4f1a\u5e94\u7528 Apex \u9650\u5236\u3002\u5982\u679c\u60a8\u7684 JavaScript \u4ee3\u7801\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u65b9\u5f0f\u8c03\u7528\u591a\u4e2a Apex \u65b9\u6cd5\uff0c\u5219 Apex \u9650\u5236\u5c06\u5206\u522b\u5e94\u7528\u4e8e\u6bcf\u4e2a\u65b9\u6cd5\u8c03\u7528\u3002<code>@wire<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"import-apex-methods\">\u5bfc\u5165 Apex \u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 JavaScript \u4e2d\u7684\u9ed8\u8ba4\u5bfc\u5165\u8bed\u6cd5\u901a\u8fc7\u4f5c\u7528\u57df\u5305\u5bfc\u5165 Apex \u65b9\u6cd5\u3002<code>@salesforce\/apex<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bed\u6cd5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>import apexMethodName from \"@salesforce\/apex\/namespace.classname.apexMethodReference\";<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>apexMethodName<\/code>&#8211; \u6807\u8bc6 Apex \u65b9\u6cd5\u7684\u7b26\u53f7\u3002<\/li>\n\n\n\n<li><code>apexMethodReference<\/code>&#8211; \u8981\u5bfc\u5165\u7684 Apex \u65b9\u6cd5\u7684\u540d\u79f0\u3002<\/li>\n\n\n\n<li><code>classname<\/code>&#8211; Apex \u7c7b\u7684\u540d\u79f0\u3002<\/li>\n\n\n\n<li><code>namespace<\/code>&#8211; \u5982\u679c\u7c7b\u4e0e\u7ec4\u4ef6\u4f4d\u4e8e\u540c\u4e00\u547d\u540d\u7a7a\u95f4\u4e2d\uff0c\u5219\u4e0d\u8981\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\u3002\u5982\u679c\u8be5\u7c7b\u4f4d\u4e8e\u6258\u7ba1\u5305\u4e2d\uff0c\u8bf7\u6307\u5b9a\u6258\u7ba1\u5305\u7684\u547d\u540d\u7a7a\u95f4\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u7528\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53 Apex \u7c7b\u540d\u79f0\u5728 JavaScript \u6e90\u6587\u4ef6\u4e4b\u5916\u53d1\u751f\u66f4\u6539\u65f6\uff0c\u8be5\u7c7b\u540d\u79f0\u4f1a\u5728 JavaScript \u6e90\u6587\u4ef6\u4e2d\u81ea\u52a8\u66f4\u65b0\u3002JavaScript \u6e90\u6587\u4ef6\u4e2d\u4e0d\u4f1a\u66f4\u65b0\u65b9\u6cd5\u548c\u53c2\u6570\u540d\u79f0\u66f4\u6539\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u8c03\u7528 Apex \u65b9\u6cd5\uff0cLightning Web \u7ec4\u4ef6\u53ef\u4ee5\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5c06 Apex \u65b9\u6cd5\u8fde\u63a5\u5230 Lightning Web \u7ec4\u4ef6<\/li>\n\n\n\n<li>\u547d\u4ee4\u5f0f\u8c03\u7528 Apex \u65b9\u6cd5<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"expose-apex-methods-to-lightning-web-components\">\u5411 Lightning Web \u7ec4\u4ef6\u516c\u5f00 Apex \u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5411 Lightning Web \u7ec4\u4ef6\u516c\u5f00 Apex \u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u5fc5\u987b\u662f and \u6216 \u3002\u7528 \u6ce8\u91ca\u65b9\u6cd5\u3002<code>staticglobalpublic@AuraEnabled<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8bed\u6cd5<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ContactController {\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Contact&gt; getContactList() {\n        return &#91;\n            SELECT Id, Name, Title, Phone, Email, Picture__c\n            FROM Contact\n            WHERE Picture__c != null\n            WITH SECURITY_ENFORCED\n            LIMIT 10\n        ];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8f93\u5165\u548c\u8f93\u51fa\u652f\u6301\u8fd9\u4e9b\u7c7b\u578b\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u57fa\u5143\u00a0&#8211; Boolean\u3001Date\u3001DateTime\u3001Decimal\u3001Double\u3001Integer\u3001Long \u548c String\u3002<\/li>\n\n\n\n<li>sObject\u00a0&#8211; \u652f\u6301\u6807\u51c6\u548c\u81ea\u5b9a\u4e49 sObject\u3002<\/li>\n\n\n\n<li>Apex &#8211;\u00a0Apex\u00a0\u7c7b\u7684\u5b9e\u4f8b\u3002 \uff08\u6700\u5e38\u89c1\u7684\u662f\u81ea\u5b9a\u4e49\u7c7b\u3002<\/li>\n\n\n\n<li>\u96c6\u5408\u00a0&#8211; \u4efb\u4f55\u5176\u4ed6\u7c7b\u578b\u7684\u96c6\u5408\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4e0d\u652f\u6301\u5c06 Apex \u5185\u90e8\u7c7b\u4f5c\u4e3a Lightning Web \u7ec4\u4ef6\u8c03\u7528\u7684 Apex \u65b9\u6cd5\u7684\u53c2\u6570\u6216\u8fd4\u56de\u503c\u3002<\/li>\n\n\n\n<li>\u4e0d\u652f\u6301\u4ece Lightning Web \u7ec4\u4ef6\u5f15\u7528\u7684 Apex \u65b9\u6cd5\u7684 Apex \u6ce8\u91ca\u3002\u4ece\u8f6f\u4ef6\u5305\u5b89\u88c5\u7684 Lightning Web \u7ec4\u4ef6\u65e0\u6cd5\u4ece\u53e6\u4e00\u4e2a\u8f6f\u4ef6\u5305\u4e2d\u7684 Apex \u7c7b\u8c03\u7528 Apex \u65b9\u6cd5\uff0c\u5373\u4f7f\u4e24\u4e2a\u8f6f\u4ef6\u5305\u4f4d\u4e8e\u540c\u4e00\u547d\u540d\u7a7a\u95f4\u4e2d\u4e5f\u662f\u5982\u6b64\u3002<code>@NamespaceAccessible<\/code><code>@AuraEnabled<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u7528\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Lightning \u7ec4\u4ef6\u6846\u67b6\u4e0d\u5f3a\u5236\u6267\u884c\u4efb\u4f55\u6709\u5173 Apex \u7c7b\u4f4d\u7f6e\u7684\u89c4\u5219\u3002\u5982\u679c\u60a8\u4f7f\u7528\u7684\u662f Salesforce DX\uff0c\u8bf7\u5c06 Apex \u7c7b\u653e\u5728\u76ee\u5f55\u4e2d\u3002<code>&lt;app dir&gt;\/main\/default\/classes<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6784\u9020 Apex \u65b9\u6cd5\u65f6\uff0c\u5fc5\u987b\u51b3\u5b9a\u662f\u5c06\u53c2\u6570\u4f5c\u4e3a\u57fa\u5143\u4f20\u5165\uff0c\u8fd8\u662f\u4f5c\u4e3a\u590d\u6742\u6570\u636e\u7c7b\u578b\uff08\u5982 Apex \u7c7b\u6216 sObject\uff09\u4f20\u5165\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63d0\u793a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lwc-recipes\u00a0\u5b58\u50a8\u5e93\u6709\u4e00\u4e2a apexImperativeMethodWithParams \u548c\u00a0<code>apexImperativeMethodWithComplexParams<\/code>\u00a0\u7ec4\u4ef6\u793a\u4f8b\uff0c\u8be5\u793a\u4f8b\u8c03\u7528\u5177\u6709\u57fa\u5143\u6216\u590d\u6742\u53c2\u6570\u7684\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"wire-apex-methods-to-lightning-web-components\">\u5c06 Apex \u65b9\u6cd5\u8fde\u63a5\u5230 Lightning Web \u7ec4\u4ef6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u8bfb\u53d6 Salesforce \u6570\u636e\uff0cLightning Web \u7ec4\u4ef6\u4f7f\u7528\u53cd\u5e94\u5f0f\u8fde\u7ebf\u670d\u52a1\u3002\u5728\u7ec4\u4ef6\u7684 JavaScript \u7c7b\u4e2d\u7528\u4e8e\u6307\u5b9a Apex \u65b9\u6cd5\u3002\u53ef\u4ee5\u4f7f\u7528\u5c5e\u6027\u6216\u51fd\u6570\u6765\u63a5\u6536\u6570\u636e\u3002\u8981\u5bf9\u8fd4\u56de\u7684\u6570\u636e\u8fdb\u884c\u64cd\u4f5c\uff0c\u9700\u8981\u51fd\u6570\u3002<code>@wire<\/code><code>@wire<\/code><code>@wire<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u7528\u4e8e\u8c03\u7528 Apex \u65b9\u6cd5\uff0c\u8bf7\u4f7f\u7528 \u6279\u6ce8 Apex \u65b9\u6cd5\u3002\u5728\u53d1\u51fa\u7f51\u7edc\u8c03\u7528\u4ee5\u8c03\u7528\u670d\u52a1\u5668\u4e0a\u7684 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u5c06\u68c0\u67e5\u5ba2\u6237\u7aef Lightning \u6570\u636e\u670d\u52a1\u7f13\u5b58\u3002\u8981\u5237\u65b0\u8fc7\u65f6\u7684\u6570\u636e\uff0c\u8bf7\u8c03\u7528 \uff0c\u56e0\u4e3a Lightning \u6570\u636e\u670d\u52a1\u4e0d\u7ba1\u7406 Apex \u9884\u7f6e\u7684\u6570\u636e\u3002<code>@wire<\/code><code>@AuraEnabled(cacheable=true)<\/code><code>refreshApex()<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u6b64\u8bed\u6cd5\u5bfc\u5165 Apex \u65b9\u6cd5\u5e76\u5c06\u5176\u8fde\u63a5\u5230\u7ec4\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import apexMethodName from '@salesforce\/apex\/namespace.classname.apexMethodReference';\n@wire(apexMethodName, { apexMethodParams })\npropertyOrFunction;<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>apexMethodName<\/code>&#8211; \u6807\u8bc6 Apex \u65b9\u6cd5\u7684\u7b26\u53f7\u3002<\/li>\n\n\n\n<li><code>apexMethodReference<\/code>&#8211; \u8981\u5bfc\u5165\u7684 Apex \u65b9\u6cd5\u7684\u540d\u79f0\u3002<\/li>\n\n\n\n<li><code>classname<\/code>&#8211; Apex \u7c7b\u7684\u540d\u79f0\u3002<\/li>\n\n\n\n<li><code>namespace<\/code>&#8211; Salesforce \u7ec4\u7ec7\u7684\u547d\u540d\u7a7a\u95f4\u3002\u6307\u5b9a\u547d\u540d\u7a7a\u95f4\uff0c\u9664\u975e\u7ec4\u7ec7\u4f7f\u7528\u9ed8\u8ba4\u547d\u540d\u7a7a\u95f4 \uff08\uff09\uff0c\u5728\u8fd9\u79cd\u60c5\u51b5\u4e0b\uff0c\u8bf7\u52ff\u6307\u5b9a\u5b83\u3002<code>c<\/code><\/li>\n\n\n\n<li><code>apexMethodParams<\/code>&#8211; \u5177\u6709\u4e0e \u7684\u53c2\u6570\u5339\u914d\u7684\u5c5e\u6027\uff08\u5982\u679c\u9700\u8981\uff09\u7684\u5bf9\u8c61\u3002\u5982\u679c\u53c2\u6570\u503c\u4e3a \uff0c\u5219\u8c03\u7528\u8be5\u65b9\u6cd5\u3002\u5982\u679c\u53c2\u6570\u503c\u4e3a \uff0c\u5219\u4e0d\u8c03\u7528\u8be5\u65b9\u6cd5\u3002\u5982\u679c Apex \u65b9\u6cd5\u91cd\u8f7d\uff0c\u5219\u9009\u62e9\u8981\u8c03\u7528\u7684\u65b9\u6cd5\u7684\u9009\u62e9\u662f\u4e0d\u786e\u5b9a\u7684\uff08\u5b9e\u9645\u4e0a\u662f\u968f\u673a\u7684\uff09\uff0c\u5e76\u4e14\u4f20\u9012\u7684\u53c2\u6570\u73b0\u5728\u6216\u5c06\u6765\u53ef\u80fd\u4f1a\u5bfc\u81f4\u9519\u8bef\u3002\u4e0d\u8981\u91cd\u8f7d Apex \u65b9\u6cd5\u3002<code>apexMethodnullundefined@AuraEnabled<\/code>\u91cd\u8981<code>apexMethodParams<\/code>\u662f\u4e00\u4e2a\u5bf9\u8c61\u3002\u82e5\u8981\u5c06\u53c2\u6570\u503c\u4f20\u9012\u7ed9 Apex \u65b9\u6cd5\uff0c\u8bf7\u4f20\u9012\u5176\u5c5e\u6027\u4e0e Apex \u65b9\u6cd5\u7684\u53c2\u6570\u5339\u914d\u7684\u5bf9\u8c61\u3002\u4f8b\u5982\uff0c\u5982\u679c Apex \u65b9\u6cd5\u91c7\u7528\u5b57\u7b26\u4e32\u53c2\u6570\uff0c\u5219\u4e0d\u8981\u76f4\u63a5\u4f20\u9012\u5b57\u7b26\u4e32\u3002\u76f8\u53cd\uff0c\u8bf7\u4f20\u9012\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u5305\u542b\u503c\u4e3a\u5b57\u7b26\u4e32\u7684\u5c5e\u6027\u3002\u547d\u4ee4\u5f0f\u548c\u6709\u7ebf Apex \u8c03\u7528\u90fd\u4e0d\u652f\u6301\u4f7f\u7528\u6620\u5c04\u3002\u8bf7\u53c2\u9605\u5c06\u503c\u4f20\u9012\u7ed9 Apex\u3002<\/li>\n\n\n\n<li><code>propertyOrFunction<\/code>&#8211; \u4ece\u7ebf\u8def\u670d\u52a1\u63a5\u6536\u6570\u636e\u6d41\u7684\u79c1\u6709\u5c5e\u6027\u6216\u51fd\u6570\u3002\u5982\u679c\u5c5e\u6027\u88ab\u4fee\u9970\u4e3a \uff0c\u5219\u7ed3\u679c\u5c06\u8fd4\u56de\u5230\u8be5\u5c5e\u6027\u7684\u5c5e\u6027\u6216\u5c5e\u6027\u3002\u5982\u679c\u51fd\u6570\u7528 \u4fee\u9970\uff0c\u5219\u7ed3\u679c\u5c06\u5728\u5177\u6709\u5c5e\u6027\u6216\u5c5e\u6027\u7684\u5bf9\u8c61\u4e2d\u8fd4\u56de\u3002<code>@wire<\/code><code>data<\/code><code>error<\/code><code>@wire<\/code><code>data<\/code><code>error<\/code>\u6ce8\u610f\u5c5e\u6027\u548c\u5c5e\u6027\u662f API \u4e2d\u7684\u786c\u7f16\u7801\u503c\u3002\u60a8\u5fc5\u987b\u4f7f\u7528\u8fd9\u4e9b\u503c\u3002<code>data<\/code><code>error<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c06 Apex \u65b9\u6cd5\u8fde\u63a5\u5230\u5c5e\u6027<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u00a0lwc-recipes\u00a0\u5b58\u50a8\u5e93\u4e2d\u7684\u7ec4\u4ef6\u3002\u6b64\u7ec4\u4ef6\u6253\u5370 Apex \u65b9\u6cd5\u8fd4\u56de\u7684\u8054\u7cfb\u4eba\u5217\u8868\u3002<code>apexWireMethodToProperty<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"419\" height=\"192\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_to_prop.png\" alt=\"\" class=\"wp-image-3874\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_to_prop.png 419w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_to_prop-300x137.png 300w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u83b7\u53d6\u5176\u6570\u636e\uff0c\u8be5\u7ec4\u4ef6\u8fde\u63a5\u4e86\u4e00\u4e2a Apex \u65b9\u6cd5\u3002Apex \u65b9\u6cd5\u8fdb\u884c SOQL \u67e5\u8be2\uff0c\u8be5\u67e5\u8be2\u8fd4\u56de\u6bcf\u4e2a\u8054\u7cfb\u4eba\u90fd\u6709\u56fe\u7247\u7684\u8054\u7cfb\u4eba\u5217\u8868\u3002\uff08\u6b64\u7ec4\u4ef6\u4e0d\u5448\u73b0\u56fe\u7247\uff0c\u4f46\u5176\u4ed6\u793a\u4f8b\u7ec4\u4ef6\u4f1a\u5448\u73b0\u3002\u6b63\u5982\u6211\u4eec\u6240\u4e86\u89e3\u7684\uff0c\u8981\u8fd4\u56de\u4e00\u4e2a\u7b80\u5355\u7684\u8054\u7cfb\u4eba\u5217\u8868\uff0c\u6700\u597d\u4f7f\u7528\u00a0<code>getListUi<\/code>\u3002\u4f46\u662f\u8981\u4f7f\u7528 SOQL \u67e5\u8be2\u6765\u9009\u62e9\u67d0\u4e9b\u8bb0\u5f55\uff0c\u6211\u4eec\u5fc5\u987b\u4f7f\u7528 Apex \u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u8bb0\u4f4f\uff0c\u8be5\u65b9\u6cd5\u5fc5\u987b\u662f \u3001 \u548c \u6216 \u3002\u8be5\u65b9\u6cd5\u5fc5\u987b\u7528 \u4fee\u9970\u3002<code>static<\/code><code>global<\/code><code>public<\/code><code>@AuraEnabled(cacheable=true)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ContactController {\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Contact&gt; getContactList() {\n        return &#91;\n            SELECT Id, Name, Title, Phone, Email, Picture__c\n            FROM Contact\n            WHERE Picture__c != null\n            WITH SECURITY_ENFORCED\n            LIMIT 10\n        ];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u7ec4\u4ef6\u7684 JavaScript \u4ee3\u7801\u5bfc\u5165 Apex \u65b9\u6cd5\uff0c\u5e76\u901a\u8fc7 wire \u670d\u52a1\u8c03\u7528\u5b83\u3002\u7535\u6c47\u670d\u52a1\u8981\u4e48\u8bbe\u7f6e\u5c5e\u6027\u7684\u8054\u7cfb\u4eba\u5217\u8868\uff0c\u8981\u4e48\u5411\u5c5e\u6027\u8fd4\u56de\u9519\u8bef\u3002<code>contacts.data<\/code><code>contacts.error<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ apexWireMethodToProperty.js\nimport { LightningElement, wire } from \"lwc\";\nimport getContactList from \"@salesforce\/apex\/ContactController.getContactList\";\n\nexport default class ApexWireMethodToProperty extends LightningElement {\n  @wire(getContactList) contacts;\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u6a21\u677f\u4f7f\u7528\u00a0<code>lwc\uff1aif<\/code>\u00a0\u6307\u4ee4\u6765\u68c0\u67e5\u5c5e\u6027\u662f\u5426\u4e3a\u771f\u503c\u3002\u5982\u679c\u662f\uff0c\u5b83\u4f1a\u5faa\u73af\u8bbf\u95ee\u5b83\u5e76\u5448\u73b0\u6bcf\u4e2a\u8054\u7cfb\u4eba\u7684\u540d\u79f0\u3002\u5982\u679c\u4e3a truey\uff0c\u5219\u7ec4\u4ef6\u5448\u73b0 .<code>contacts.datacontacts.error&lt;c-error-panel><\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- apexWireMethodToProperty.html --&gt;\n&lt;template&gt;\n  &lt;lightning-card title=\"ApexWireMethodToProperty\" icon-name=\"custom:custom63\"&gt;\n    &lt;div class=\"slds-m-around_medium\"&gt;\n      &lt;template lwc:if={contacts.data}&gt;\n        &lt;template for:each={contacts.data} for:item=\"contact\"&gt;\n          &lt;p key={contact.Id}&gt;{contact.Name}&lt;\/p&gt;\n        &lt;\/template&gt;\n      &lt;\/template&gt;\n      &lt;template lwc:elseif={contacts.error}&gt;\n        &lt;c-error-panel errors={contacts.error}&gt;&lt;\/c-error-panel&gt;\n      &lt;\/template&gt;\n    &lt;\/div&gt;\n  &lt;\/lightning-card&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528\u52a8\u6001\u53c2\u6570\u8fde\u63a5 Apex \u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\uff0c\u8ba9\u6211\u4eec\u8fde\u63a5\u4e00\u4e2a\u63a5\u53d7\u53c2\u6570\u7684 Apex \u65b9\u6cd5\u3002\u6b64\u7ec4\u4ef6\u4e5f\u5728\u00a0lwc-recipes\u00a0\u5b58\u50a8\u5e93\u4e2d\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"419\" height=\"184\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_params.png\" alt=\"\" class=\"wp-image-3876\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_params.png 419w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_params-300x132.png 300w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u65b9\u6cd5\u91c7\u7528\u4e00\u4e2a\u540d\u4e3a \u7684\u5b57\u7b26\u4e32\u53c2\u6570\uff0c\u5e76\u8fd4\u56de\u5176\u540d\u79f0\u5305\u542b\u8be5\u5b57\u7b26\u4e32\u7684\u8054\u7cfb\u4eba\u5217\u8868\u3002<code>searchKey<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ ContactController.cls\npublic with sharing class ContactController {\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Contact&gt; findContacts(String searchKey) {\n        String key = '%' + searchKey + '%';\n        return &#91;\n            SELECT Id, Name, Title, Phone, Email, Picture__c\n            FROM Contact\n            WHERE Name LIKE :key AND Picture__c != null\n            WITH SECURITY_ENFORCED\n            LIMIT 10\n        ];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7ec4\u4ef6\u7684 JavaScript \u5728\u53c2\u6570\u503c\u524d\u9762\u52a0\u4e0a \uff0c\u4ee5\u6307\u793a\u5b83\u662f\u52a8\u6001\u7684\u548c\u53cd\u5e94\u5f0f\u7684\u3002\u5b83\u5f15\u7528\u7ec4\u4ef6\u5b9e\u4f8b\u7684\u5c5e\u6027\u3002\u5982\u679c\u5176\u503c\u53d1\u751f\u66f4\u6539\uff0c\u6a21\u677f\u5c06\u91cd\u65b0\u5448\u73b0\u3002<code>searchKey<\/code><code>$<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u91cd\u8981<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bf9\u4e8e Apex \u65b9\u6cd5\u7684\u7ec4\u4ef6\uff0c\u7b2c\u4e00\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u5b57\u7b26\u4e32\uff0c\u5b83\u662f Apex \u65b9\u6cd5\u7684\u540d\u79f0\uff0c\u5728\u672c\u4f8b\u4e2d\u4e3a .\u7b2c\u4e8c\u4e2a\u53c2\u6570\u662f\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5176\u4e2d\u5305\u542b\u8981\u4f20\u9012\u7ed9 Apex \u65b9\u6cd5\u7684\u53c2\u6570\u3002\u56e0\u6b64\uff0c\u4f8b\u5982\uff0c\u5373\u4f7f\u91c7\u7528\u5b57\u7b26\u4e32\uff0c\u6211\u4eec\u4e5f\u4e0d\u4f1a\u5c06\u5b57\u7b26\u4e32\u4f5c\u4e3a\u7b2c\u4e8c\u4e2a\u53c2\u6570\u4f20\u9012\u3002\u76f8\u53cd\uff0c\u6211\u4eec\u4f20\u9012\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u5305\u542b\u4e00\u4e2a\u5c5e\u6027\uff0c\u5176\u503c\u4e3a\u5b57\u7b26\u4e32\uff1a \u3002\uff08\u5982\u679c Apex \u65b9\u6cd5\u91c7\u7528\u53e6\u4e00\u4e2a\u53c2\u6570\uff0c\u6211\u4eec\u5c06\u5411\u5bf9\u8c61\u6dfb\u52a0\u53e6\u4e00\u4e2a\u5c5e\u6027\u3002<code>@wire<\/code><code>findContacts<\/code><code>@wire<\/code><code>findContacts<\/code><code>@wire<\/code><code>{ searchKey: '$searchKey' }<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ apexWireMethodWithParams.js\nimport { LightningElement, wire } from \"lwc\";\nimport findContacts from \"@salesforce\/apex\/ContactController.findContacts\";\n\n\/** The delay used when debouncing event handlers before invoking Apex. *\/\nconst DELAY = 300;\n\nexport default class ApexWireMethodWithParams extends LightningElement {\n  searchKey = \"\";\n\n  @wire(findContacts, { searchKey: \"$searchKey\" })\n  contacts;\n\n  handleKeyChange(event) {\n    \/\/ Debouncing this method: Do not update the reactive property as long as this function is\n    \/\/ being called within a delay of DELAY. This is to avoid a very large number of Apex method calls.\n    window.clearTimeout(this.delayTimeout);\n    const searchKey = event.target.value;\n    this.delayTimeout = setTimeout(() =&gt; {\n      this.searchKey = searchKey;\n    }, DELAY);\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6a21\u677f\u7528\u4f5c\u5b57\u6bb5\u3002<code>searchKey<\/code><code>value<\/code><code>&lt;lightning-input&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- apexWireMethodWithParams.html --&gt;\n&lt;template&gt;\n  &lt;lightning-card title=\"ApexWireMethodWithParams\" icon-name=\"custom:custom63\"&gt;\n    &lt;div class=\"slds-m-around_medium\"&gt;\n      &lt;lightning-input\n        type=\"search\"\n        onchange={handleKeyChange}\n        class=\"slds-m-bottom_small\"\n        label=\"Search\"\n        value={searchKey}\n      &gt;&lt;\/lightning-input&gt;\n      &lt;template lwc:if={contacts.data}&gt;\n        &lt;template for:each={contacts.data} for:item=\"contact\"&gt;\n          &lt;p key={contact.Id}&gt;{contact.Name}&lt;\/p&gt;\n        &lt;\/template&gt;\n      &lt;\/template&gt;\n      &lt;template lwc:elseif={contacts.error}&gt;\n        &lt;c-error-panel errors={contacts.error}&gt;&lt;\/c-error-panel&gt;\n      &lt;\/template&gt;\n    &lt;\/div&gt;\n  &lt;\/lightning-card&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u63d0\u793a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u89c2\u770b\u6b64\u793a\u4f8b\u4ee3\u7801\u7684\u6f14\u793a\uff0c\u8bf7\u53c2\u9605\u00a0Lightning Web \u7ec4\u4ef6\u89c6\u9891\u5e93\u4e2d\u7684<strong>\u5c06 Apex \u65b9\u6cd5\u8fde\u63a5\u5230\u5c5e\u6027<\/strong>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8fde\u63a5\u5177\u6709\u590d\u6742\u53c2\u6570\u7684 Apex \u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u8c03\u7528\u5c06\u5bf9\u8c61\u4f5c\u4e3a\u53c2\u6570\u7684 Apex \u65b9\u6cd5\u3002\u4efb\u4f55 Apex \u65b9\u6cd5\u7684\u8bed\u6cd5\u90fd\u662f\u76f8\u540c\u7684\uff0c\u4f46\u6b64\u793a\u4f8b\u663e\u793a\u4e86\u7528\u4e8e\u751f\u6210\u548c\u4f20\u9012\u5bf9\u8c61\u7684\u6a21\u5f0f\u3002<code>@wire<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u7ec4\u4ef6\u6709\u4e09\u4e2a\u8f93\u5165\u5b57\u6bb5\uff0c\u8fd9\u4e9b\u5b57\u6bb5\u91c7\u7528\u4e00\u4e2a\u5b57\u7b26\u4e32\u3001\u4e00\u4e2a\u6570\u5b57\u548c\u591a\u4e2a\u5217\u8868\u9879\uff0c\u7ec4\u4ef6\u4f7f\u7528\u8fd9\u4e9b\u5b57\u6bb5\u6765\u751f\u6210\u5217\u8868\u3002Apex \u65b9\u6cd5\u53ea\u662f\u6839\u636e\u503c\u8fde\u63a5\u5e76\u8fd4\u56de\u4e00\u4e2a\u5b57\u7b26\u4e32\u3002\u5f53\u8f93\u5165\u503c\u53d1\u751f\u66f4\u6539\u65f6\uff0c\u5c06\u8c03\u7528 Apex \u65b9\u6cd5\u5e76\u9884\u914d\u65b0\u6570\u636e\u3002<code>@wire<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img decoding=\"async\" width=\"578\" height=\"390\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apexWireMethodComplexParam.png\" alt=\"\" class=\"wp-image-3875\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apexWireMethodComplexParam.png 578w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apexWireMethodComplexParam-300x202.png 300w\" sizes=\"(max-width: 578px) 100vw, 578px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- apexWireMethodWithComplexParams.html --&gt;\n&lt;template&gt;\n  &lt;lightning-card title=\"ApexWireMethodWithComplexParams\" icon-name=\"custom:custom63\"&gt;\n    &lt;div class=\"slds-var-m-around_medium\"&gt;\n      &lt;lightning-input\n        label=\"String\"\n        type=\"string\"\n        value={stringValue}\n        class=\"string-input\"\n        onchange={handleStringChange}\n      &gt;&lt;\/lightning-input&gt;\n      &lt;lightning-input\n        label=\"Number\"\n        type=\"number\"\n        min=\"0\"\n        max=\"100\"\n        value={numberValue}\n        class=\"number-input\"\n        onchange={handleNumberChange}\n      &gt;&lt;\/lightning-input&gt;\n      &lt;lightning-input\n        label=\"List items\"\n        type=\"number\"\n        min=\"0\"\n        max=\"10\"\n        value={listItemValue}\n        class=\"list-item-input\"\n        onchange={handleListItemChange}\n      &gt;&lt;\/lightning-input&gt;\n      &lt;br \/&gt;\n      &lt;template lwc:if={apexResponse.data}&gt;\n        &lt;p&gt;{apexResponse.data}&lt;\/p&gt;\n      &lt;\/template&gt;\n    &lt;\/div&gt;\n    &lt;template lwc:elseif={apexResponse.error}&gt;\n      &lt;c-error-panel errors={error}&gt;&lt;\/c-error-panel&gt;\n    &lt;\/template&gt;\n  &lt;\/lightning-card&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u65b9\u6cd5\u91c7\u7528\u4e00\u4e2a\u5bf9\u8c61 \u3002<code>CustomWrapper<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ApexTypesController {\n    @AuraEnabled(cacheable=true)\n    public static String checkApexTypes(CustomWrapper wrapper) {\n        \/\/ The values are based on the data that is defined in the\n        \/\/ apexWireMethodWithComplexParams Lightning web component.\n        String response =\n            'You entered \"' +\n            wrapper.someString +\n            '\" as String, and \"' +\n            wrapper.someInteger +\n            '\" as Integer value. The list contained ' +\n            wrapper.someList.size() +\n            ' items.';\n        return response;\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class CustomWrapper {\n    @TestVisible\n    class InnerWrapper {\n        @AuraEnabled\n        public Integer someInnerInteger { get; set; }\n        @AuraEnabled\n        public String someInnerString { get; set; }\n    }\n\n    @AuraEnabled\n    public Integer someInteger { get; set; }\n    @AuraEnabled\n    public String someString { get; set; }\n    @AuraEnabled\n    public List&lt;InnerWrapper&gt; someList { get; set; }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u5c06\u53c2\u6570\u503c\u4ece\u7ec4\u4ef6\u4f20\u9012\u5230 Apex \u65b9\u6cd5\uff0c\u8bf7\u4f7f\u7528\u5bf9\u8c61\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0cApex \u65b9\u6cd5\u91c7\u7528\u4e00\u4e2a\u5bf9\u8c61 \uff0c\u56e0\u6b64\u8be5\u7ec4\u4ef6\u4f1a\u751f\u6210\u4e00\u4e2a\u5339\u914d\u7684\u5bf9\u8c61\u4ee5\u4f20\u5165 .<code>CustomWrapper<\/code><code>@wire<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ apexWireMethodWithComplexParams.js\nimport { LightningElement, wire } from \"lwc\";\nimport checkApexTypes from \"@salesforce\/apex\/ApexTypesController.checkApexTypes\";\n\nexport default class ApexWireMethodWithComplexParams extends LightningElement {\n  listItemValue = 0;\n  numberValue = 50;\n  stringValue = \"Some string\";\n\n  parameterObject = {\n    someString: this.stringValue,\n    someInteger: this.numberValue,\n    someList: &#91;],\n  };\n\n  @wire(checkApexTypes, { wrapper: \"$parameterObject\" })\n  apexResponse;\n\n  handleStringChange(event) {\n    this.parameterObject = {\n      ...this.parameterObject,\n      someString: (this.stringValue = event.target.value),\n    };\n  }\n\n  handleNumberChange(event) {\n    this.parameterObject = {\n      ...this.parameterObject,\n      someInteger: (this.numberValue = parseInt(event.target.value, 10)),\n    };\n  }\n\n  handleListItemChange(event) {\n    const someList = &#91;];\n    for (let i = 0; i &lt; event.target.value; i++) {\n      someList.push({\n        someInnerString: this.stringValue,\n        someInnerInteger: this.numberValue,\n      });\n    }\n    this.parameterObject = {\n      ...this.parameterObject,\n      someList,\n    };\n  }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c06 Apex \u65b9\u6cd5\u8fde\u63a5\u5230\u51fd\u6570<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u00a0lwc-recipes\u00a0\u5b58\u50a8\u5e93\u4e2d\u7684\u7ec4\u4ef6\u3002\u6b64\u7ec4\u4ef6\u5c06 Apex \u65b9\u6cd5\u8c03\u7528\u8fde\u63a5\u5230\u51fd\u6570\u3002\u7531\u4e8e\u7ed3\u679c\u88ab\u9884\u914d\u5230\u51fd\u6570\uff0c\u56e0\u6b64 JavaScript \u53ef\u4ee5\u5bf9\u7ed3\u679c\u8fdb\u884c\u64cd\u4f5c\u3002\u6b64\u5916\uff0c\u6a21\u677f\u8bbf\u95ee\u6570\u636e\u7684\u65b9\u5f0f\u4e0e\u5c06\u7ed3\u679c\u9884\u914d\u5230\u5c5e\u6027\u65f6\u7565\u6709\u4e0d\u540c\u3002<code>apexWireMethodToFunction<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6e32\u67d3\u7684\u7ec4\u4ef6\u4e0e\uff08\u6807\u5934\u9664\u5916\uff09\u76f8\u540c\u3002<code>apexWireMethodToProperty<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"419\" height=\"192\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_to_function.png\" alt=\"\" class=\"wp-image-3877\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_to_function.png 419w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_wire_to_function-300x137.png 300w\" sizes=\"(max-width: 419px) 100vw, 419px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u7ec4\u4ef6\u8c03\u7528\u4e0e \u76f8\u540c\u7684 Apex \u65b9\u6cd5\u3002\u8be5\u65b9\u6cd5\u5fc5\u987b\u662f \u3001 \u548c \u6216 \u3002\u8be5\u65b9\u6cd5\u5fc5\u987b\u7528 \u4fee\u9970\u3002<code>apexWireMethodToProperty<\/code><code>static<\/code><code>global<\/code><code>public<\/code><code>@AuraEnabled(cacheable=true)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ ContactController.cls\npublic with sharing class ContactController {\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Contact&gt; getContactList() {\n        return &#91;\n            SELECT Id, Name, Title, Phone, Email, Picture__c\n            FROM Contact\n            WHERE Picture__c != null\n            WITH SECURITY_ENFORCED\n            LIMIT 10\n        ];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u7ec4\u4ef6\u7684 JavaScript \u4ee3\u7801\u5bfc\u5165 Apex \u65b9\u6cd5\uff0c\u5e76\u901a\u8fc7 wire \u670d\u52a1\u8c03\u7528\u5b83\u3002\u7ebf\u8def\u670d\u52a1\u901a\u8fc7\u5177\u6709 or \u5c5e\u6027\u7684\u5bf9\u8c61\u5c06\u7ed3\u679c\u63d0\u4f9b\u7ed9\u51fd\u6570\u3002\u5982\u679c\u7535\u6c47\u670d\u52a1\u63d0\u4f9b \uff0c\u5219\u5c06\u5176\u5206\u914d\u7ed9 \uff0c\u8be5\u6a21\u677f\u5c06\u7528\u4e8e\u3002\u5982\u679c\u5b83\u63d0\u4f9b \uff0c\u5219\u5c06\u5176\u5206\u914d\u7ed9 \uff0c\u8be5\u6a21\u677f\u4e2d\u4e5f\u4f1a\u4f7f\u7528\u3002\u5982\u679c\u8fd9\u4e9b\u5c5e\u6027\u7684\u503c\u53d1\u751f\u66f4\u6539\uff0c\u6a21\u677f\u5c06\u91cd\u65b0\u5448\u73b0\u3002<code>wiredContacts()<\/code><code>error<\/code><code>data<\/code><code>data<\/code><code>this.contacts<\/code><code>error<\/code><code>this.error<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ apexWireMethodToFunction.js\nimport { LightningElement, wire } from \"lwc\";\nimport getContactList from \"@salesforce\/apex\/ContactController.getContactList\";\n\nexport default class ApexWireMethodToFunction extends LightningElement {\n  contacts;\n  error;\n\n  @wire(getContactList)\n  wiredContacts({ error, data }) {\n    if (data) {\n      this.contacts = data;\n      this.error = undefined;\n    } else if (error) {\n      this.error = error;\n      this.contacts = undefined;\n    }\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u6a21\u677f\u4f7f\u7528\u8be5\u6307\u4ee4\u6765\u68c0\u67e5 JavaScript \u5c5e\u6027\u3002\u5982\u679c\u5b83\u5b58\u5728\uff0c\u5b83\u4f1a\u5faa\u73af\u8bbf\u95ee\u5b83\u5e76\u5448\u73b0\u6bcf\u4e2a\u8054\u7cfb\u4eba\u7684\u540d\u79f0\u3002\u5982\u679c\u8be5\u5c5e\u6027\u5b58\u5728\uff0c\u5219\u7ec4\u4ef6\u5c06\u5448\u73b0 .<code>lwc:if<\/code><code>contacts<\/code><code>error<\/code><code>&lt;c-error-panel&gt;<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- apexWireMethodToFunction.html --&gt;\n&lt;template&gt;\n  &lt;lightning-card title=\"ApexWireMethodToFunction\" icon-name=\"custom:custom63\"&gt;\n    &lt;div class=\"slds-m-around_medium\"&gt;\n      &lt;template lwc:if={contacts}&gt;\n        &lt;template for:each={contacts} for:item=\"contact\"&gt;\n          &lt;p key={contact.Id}&gt;{contact.Name}&lt;\/p&gt;\n        &lt;\/template&gt;\n      &lt;\/template&gt;\n      &lt;template lwc:elseif={error}&gt;\n        &lt;c-error-panel errors={error}&gt;&lt;\/c-error-panel&gt;\n      &lt;\/template&gt;\n    &lt;\/div&gt;\n  &lt;\/lightning-card&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"call-apex-methods-imperatively\">\u547d\u4ee4\u5f0f\u8c03\u7528 Apex \u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u63a7\u5236\u65b9\u6cd5\u8c03\u7528\u7684\u53d1\u751f\u65f6\u95f4\uff08\u4f8b\u5982\uff0c\u54cd\u5e94\u5355\u51fb\u6309\u94ae\uff09\uff0c\u8bf7\u4ee5\u547d\u4ee4\u65b9\u5f0f\u8c03\u7528\u8be5\u65b9\u6cd5\u3002\u5f53\u60a8\u4ee5\u547d\u4ee4\u65b9\u5f0f\u8c03\u7528\u67d0\u4e2a\u65b9\u6cd5\u65f6\uff0c\u60a8\u53ea\u6536\u5230\u4e00\u4e2a\u54cd\u5e94\u3002\u5c06\u6b64\u884c\u4e3a\u4e0e \u8fdb\u884c\u6bd4\u8f83\uff0c\u540e\u8005\u5c06\u63a7\u5236\u6743\u59d4\u6258\u7ed9\u6846\u67b6\uff0c\u5e76\u5bfc\u81f4\u9884\u914d\u503c\u6d41\u3002<code>@wire<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\uff0c\u5fc5\u987b\u4ee5\u547d\u4ee4\u65b9\u5f0f\u8c03\u7528 Apex \u65b9\u6cd5\uff0c\u800c\u4e0d\u662f\u4f7f\u7528 .<code>@wire<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u8c03\u7528\u672a\u6ce8\u91ca\u7684\u65b9\u6cd5\uff0c\u5176\u4e2d\u5305\u62ec\u63d2\u5165\u3001\u66f4\u65b0\u6216\u5220\u9664\u6570\u636e\u7684\u4efb\u4f55\u65b9\u6cd5\u3002<code>cacheable=true<\/code><\/li>\n\n\n\n<li>\u63a7\u5236\u8c03\u7528\u7684\u53d1\u751f\u65f6\u95f4\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u7528\u6237\u754c\u9762 API \u4e0d\u652f\u6301\u7684\u5bf9\u8c61\uff0c\u5982 Task \u548c Event\u3002<\/li>\n\n\n\n<li>\u4ece\u4e0d\u6269\u5c55\u7684 ES6 \u6a21\u5757\u8c03\u7528\u65b9\u6cd5<code>LightningElement<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c Apex \u65b9\u6cd5\u6807\u8bb0\u4e3a \uff0c\u5219\u5728\u53d1\u51fa\u7f51\u7edc\u8c03\u7528\u4ee5\u8c03\u7528\u670d\u52a1\u5668\u4e0a\u7684 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u5c06\u68c0\u67e5\u5ba2\u6237\u7aef Lightning \u6570\u636e\u670d\u52a1\u7f13\u5b58\u3002\u4f46\u662f\uff0cLightning \u6570\u636e\u670d\u52a1\u4e0d\u7ba1\u7406 Apex \u9884\u7f6e\u7684\u6570\u636e\u3002\u56e0\u6b64\uff0c\u8981\u5237\u65b0\u8fc7\u65f6\u7684\u6570\u636e\uff0c\u8bf7\u8c03\u7528 Apex \u65b9\u6cd5\uff0c\u7136\u540e\u8c03\u7528\u00a0notifyRecordUpdateAvailable\uff08recordIds\uff09\u00a0\u6765\u66f4\u65b0 Lightning \u6570\u636e\u670d\u52a1\u7f13\u5b58\u3002<code>@AuraEnabled(cacheable=true)<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8c03\u7528 Apex\u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u00a0lwc-recipes\u00a0\u5b58\u50a8\u5e93\u4e2d\u7684\u4e00\u4e2a\u793a\u4f8b\u7ec4\u4ef6\uff0c\u8be5\u7ec4\u4ef6\u4f7f\u7528\u4e0e\u524d\u9762\u793a\u4f8b\u76f8\u540c\u7684\u7c7b\u3002\u5f53\u7528\u6237\u5355\u51fb\u6309\u94ae\u65f6\uff0c\u7ec4\u4ef6\u4e0d\u4f1a\u8fde\u63a5\u5b83\uff0c\u800c\u662f\u8c03\u7528 .<code>getContactListgetContactList()<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"418\" height=\"236\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_imperative.png\" alt=\"\" class=\"wp-image-3878\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_imperative.png 418w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_imperative-300x169.png 300w\" sizes=\"(max-width: 418px) 100vw, 418px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5bfc\u5165\u7684\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a promise\u3002\u6b64\u4ee3\u7801\u5728\u7ed9\u5b9a\u4e00\u7ec4\u53c2\u6570\u7684\u60c5\u51b5\u4e0b\u63d0\u4f9b\u4e00\u6b21\u6027\u5206\u8fa8\u7387\uff0c\u800c\u00a0<code>@wire\uff08apexMethod\uff09<\/code>\u00a0\u63d0\u4f9b\u503c\u6d41\u5e76\u652f\u6301\u52a8\u6001\u53c2\u6570\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ apexImperativeMethod.js\nimport { LightningElement, track } from \"lwc\";\nimport getContactList from \"@salesforce\/apex\/ContactController.getContactList\";\n\nexport default class ApexImperativeMethod extends LightningElement {\n  @track contacts;\n  @track error;\n\n  handleLoad() {\n    getContactList()\n      .then((result) =&gt; {\n        this.contacts = result;\n      })\n      .catch((error) =&gt; {\n        this.error = error;\n      });\n  }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ContactController {\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Contact&gt; getContactList() {\n        return &#91;\n            SELECT Id, Name, Title, Phone, Email, Picture__c\n            FROM Contact\n            WHERE Picture__c != NULL\n            WITH SECURITY_ENFORCED\n            LIMIT 10\n        ];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u6a21\u677f\u7528\u4e8e\u5448\u73b0\u8054\u7cfb\u4eba\u5217\u8868\u6216\u9519\u8bef\u9762\u677f\u3002\u5b83\u8fd8\u7528\u4e8e\u904d\u5386\u8054\u7cfb\u4eba\u3002<code>lwc:if<\/code><code>for:each<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- apexImperativeMethod.html --&gt;\n&lt;template&gt;\n  &lt;lightning-card title=\"ApexImperativeMethod\" icon-name=\"custom:custom63\"&gt;\n    &lt;div class=\"slds-m-around_medium\"&gt;\n      &lt;p class=\"slds-m-bottom_small\"&gt;\n        &lt;lightning-button label=\"Load Contacts\" onclick={handleLoad}&gt;&lt;\/lightning-button&gt;\n      &lt;\/p&gt;\n      &lt;template lwc:if={contacts}&gt;\n        &lt;template for:each={contacts} for:item=\"contact\"&gt;\n          &lt;p key={contact.Id}&gt;{contact.Name}&lt;\/p&gt;\n        &lt;\/template&gt;\n      &lt;\/template&gt;\n      &lt;template lwc:elseif={error}&gt;\n        &lt;c-error-panel errors={error}&gt;&lt;\/c-error-panel&gt;\n      &lt;\/template&gt;\n    &lt;\/div&gt;\n  &lt;\/lightning-card&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528\u53c2\u6570\u8c03\u7528 Apex \u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u53c2\u6570\u503c\u4f20\u9012\u7ed9\u5176\u5c5e\u6027\u4e0e Apex \u65b9\u6cd5\u7684\u53c2\u6570\u5339\u914d\u7684\u5bf9\u8c61\u4e2d\u7684 Apex \u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u5982\u679c Apex \u65b9\u6cd5\u91c7\u7528\u5b57\u7b26\u4e32\u53c2\u6570\uff0c\u5219\u4e0d\u8981\u76f4\u63a5\u4f20\u9012\u5b57\u7b26\u4e32\u3002\u76f8\u53cd\uff0c\u8bf7\u4f20\u9012\u4e00\u4e2a\u5bf9\u8c61\uff0c\u8be5\u5bf9\u8c61\u5305\u542b\u503c\u4e3a\u5b57\u7b26\u4e32\u7684\u5c5e\u6027\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"350\" height=\"248\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apexImperativeWithParams.png\" alt=\"\" class=\"wp-image-3879\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apexImperativeWithParams.png 350w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apexImperativeWithParams-300x213.png 300w\" sizes=\"(max-width: 350px) 100vw, 350px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ apexImperativeMethodWithParams.js\n\nimport { LightningElement } from \"lwc\";\nimport findContacts from \"@salesforce\/apex\/ContactController.findContacts\";\n\nexport default class ApexImperativeMethodWithParams extends LightningElement {\n  searchKey = \"\";\n  contacts;\n  error;\n\n  handleKeyChange(event) {\n    this.searchKey = event.target.value;\n  }\n\n  handleSearch() {\n    findContacts({ searchKey: this.searchKey })\n      .then((result) =&gt; {\n        this.contacts = result;\n        this.error = undefined;\n      })\n      .catch((error) =&gt; {\n        this.error = error;\n        this.contacts = undefined;\n      });\n  }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ContactController {\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Contact&gt; findContacts(String searchKey) {\n        String key = '%' + searchKey + '%';\n        return &#91;\n            SELECT Id, Name, Title, Phone, Email, Picture__c\n            FROM Contact\n            WHERE Name LIKE :key AND Picture__c != NULL\n            WITH SECURITY_ENFORCED\n            LIMIT 10\n        ];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u63d0\u793a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lwc-recipes\u00a0\u5b58\u50a8\u5e93\u4e5f\u6709\u4e00\u4e2a\u7ec4\u4ef6\uff0c\u7528\u4e8e\u8c03\u7528\u5e26\u6709\u53c2\u6570\u7684\u65b9\u6cd5\u3002\u82e5\u8981\u8c03\u7528\u5177\u6709\u5bf9\u8c61\u53c2\u6570\u7684\u65b9\u6cd5\uff0c\u8bf7\u7b7e\u51fa\u7ec4\u4ef6\u3002<code>apexImperativeMethodWithParamsapexImperativeMethodWithComplexParams<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5c06\u503c\u4f20\u9012\u7ed9 Apex<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u8bb0\u5f55\u6570\u636e\u7b49\u503c\u4ece LWC \u4f20\u9012\u5230 Apex \u65f6\uff0c\u8bf7\u4f7f\u7528 JavaScript \u5bf9\u8c61\u6216\u6570\u7ec4\u3002\u6620\u5c04\u503c\u5728\u4f20\u9012\u7ed9 Apex \u65b9\u6cd5\u65f6\u4e0d\u4f1a\u5e8f\u5217\u5316\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u547d\u4ee4\u5f0f\u548c\u6709\u7ebf Apex \u8c03\u7528\u90fd\u4e0d\u652f\u6301\u4f7f\u7528\u6620\u5c04\u3002\u6620\u5c04\uff08\u4f8b\u5982 with \uff09\u7684\u4e0d\u5f53\u4f7f\u7528\u5141\u8bb8\u5728\u7981\u7528 LWS \u7684\u60c5\u51b5\u4e0b\u4f20\u9012\u6570\u636e\u3002\u4f46\u662f\uff0c\u542f\u7528 LWS \u540e\uff0c\u6b64\u7528\u6cd5\u4e0d\u518d\u8d77\u4f5c\u7528\u3002\u6b64\u5916\uff0c\u4e0d\u652f\u6301\u5c06\u503c\u4f20\u9012\u7ed9 Apex\u3002<code>map[key] = val<\/code><code>map.set(key, val)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Don\u2019t do this\nMap map = new Map();\nmap.set(key, val);\napexMethod({map});<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u4f7f\u7528\u8fd9\u6837\u7684 JavaScript \u5bf9\u8c61\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { LightningElement, wire } from \"lwc\";\nimport apexMethod from \"@salesforce\/apex\/ReadValues.apexMethod\";\n\nexport default class ApexValueExample extends LightningElement {\n  objVal = {};\n\n  val;\n\n  async connectedCallback() {\n    this.objVal&#91;\"one\"] = \"two\";\n    this.val = await apexMethod({ theValues: this.objVal });\n  }\n\n  @wire(apexMethod, { theValues: \"$objVal\" })\n  propertyOrFunction;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"batching-of-apex-actions\">Apex \u64cd\u4f5c\u7684\u6279\u5904\u7406<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6846\u67b6\u5728\u5c06 Apex \u64cd\u4f5c\u53d1\u9001\u5230\u670d\u52a1\u5668\u4e4b\u524d\u5c06\u5176\u6392\u961f\u3002\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u6b64\u673a\u5236\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u5bf9\u60a8\u662f\u900f\u660e\u7684\uff0c\u4f46\u5b83\u4f7f\u6846\u67b6\u80fd\u591f\u901a\u8fc7\u5c06\u591a\u4e2a\u64cd\u4f5c\u6279\u5904\u7406\u5230\u4e00\u4e2a\u8bf7\u6c42 \uff08XHR\uff09 \u4e2d\u6765\u6700\u5927\u7a0b\u5ea6\u5730\u51cf\u5c11\u7f51\u7edc\u6d41\u91cf\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u52a8\u4f5c\u7684\u6279\u5904\u7406\u4e5f\u79f0\u4e3a\u68da\u8f66\uff0c\u7c7b\u4f3c\u4e8e\u5c06\u68da\u8f66\u8026\u5408\u5728\u4e00\u8d77\u7684\u706b\u8f66\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u6846\u67b6\u4f7f\u7528\u5806\u6808\u6765\u8ddf\u8e2a\u8981\u53d1\u9001\u5230\u670d\u52a1\u5668\u7684 Apex \u64cd\u4f5c\u3002\u5f53\u6d4f\u89c8\u5668\u5728\u5ba2\u6237\u7aef\u4e0a\u5904\u7406\u5b8c\u4e8b\u4ef6\u548c JavaScript \u65f6\uff0c\u5806\u6808\u4e0a\u7684\u6392\u961f\u64cd\u4f5c\u5c06\u6279\u91cf\u53d1\u9001\u5230\u670d\u52a1\u5668\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Boxcar \u8bf7\u6c42\u4e2d\u7684\u64cd\u4f5c\u9650\u5236<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c boxcar \u8bf7\u6c42\u4e2d\u7684\u64cd\u4f5c\u8d85\u8fc7 2,500 \u4e2a\uff0c\u5219\u6846\u67b6\u5c06\u8fd4\u56de 413 HTTP \u54cd\u5e94\u72b6\u6001\u4ee3\u7801\u3002\u5982\u679c\u7528\u6237\u770b\u5230\u6b64\u7f55\u89c1\u9519\u8bef\uff0c\u8bf7\u8003\u8651\u91cd\u65b0\u8bbe\u8ba1\u81ea\u5b9a\u4e49\u7ec4\u4ef6\uff0c\u4ee5\u9075\u5faa\u6700\u4f73\u5b9e\u8df5\u5e76\u51cf\u5c11\u8bf7\u6c42\u4e2d\u7684\u64cd\u4f5c\u6570\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"client-side-caching-of-apex-method-results\">Apex \u65b9\u6cd5\u7ed3\u679c\u7684\u5ba2\u6237\u7aef\u7f13\u5b58<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u63d0\u9ad8\u8fd0\u884c\u65f6\u6027\u80fd\uff0c\u8bf7\u4f7f\u7528 \u6279\u6ce8 Apex \u65b9\u6cd5\uff0c\u8fd9\u4f1a\u5728\u5ba2\u6237\u7aef\u4e0a\u7f13\u5b58\u65b9\u6cd5\u7ed3\u679c\u3002\u8981\u8bbe\u7f6e \uff0c\u65b9\u6cd5\u53ea\u80fd\u83b7\u53d6\u6570\u636e\uff0c\u4e0d\u80fd\u6539\u53d8\uff08\u66f4\u6539\uff09\u6570\u636e\u3002<code>@AuraEnabled(cacheable=true)<\/code><code>cacheable=true<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5c06\u65b9\u6cd5\u6807\u8bb0\u4e3a\u53ef\u7f13\u5b58\u53ef\u5feb\u901f\u663e\u793a\u5ba2\u6237\u7aef\u5b58\u50a8\u4e2d\u7684\u7f13\u5b58\u6570\u636e\uff0c\u800c\u65e0\u9700\u7b49\u5f85\u670d\u52a1\u5668\u8bbf\u95ee\uff0c\u4ece\u800c\u63d0\u9ad8\u4e86\u7ec4\u4ef6\u7684\u6027\u80fd\u3002\u5982\u679c\u7f13\u5b58\u7684\u6570\u636e\u5df2\u8fc7\u65f6\uff0c\u6846\u67b6\u5c06\u4ece\u670d\u52a1\u5668\u68c0\u7d22\u6700\u65b0\u6570\u636e\u3002\u7f13\u5b58\u5bf9\u4e8e\u8fde\u63a5\u5ef6\u8fdf\u9ad8\u3001\u901f\u5ea6\u6162\u6216\u4e0d\u53ef\u9760\u7684\u7528\u6237\u7279\u522b\u6709\u76ca\u3002\u53ef\u7f13\u5b58\u65b9\u6cd5\u7684\u6027\u80fd\u66f4\u597d\uff0c\u56e0\u6b64\u8bf7\u5c3d\u53ef\u80fd\u4f7f\u7528\u5b83\u4eec\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u7528\u4e8e\u8c03\u7528 Apex \u65b9\u6cd5\uff0c\u5fc5\u987b\u8bbe\u7f6e .<code>@wire<\/code><code>cacheable=true<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4ee5\u547d\u4ee4\u65b9\u5f0f\u8c03\u7528 Apex \u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u9009\u62e9\u5c06 .<code>cacheable=true<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f13\u5b58\u5237\u65b0\u65f6\u95f4\u662f\u5728\u5b58\u50a8\u4e2d\u5237\u65b0\u6761\u76ee\u4e4b\u524d\u7684\u6301\u7eed\u65f6\u95f4\uff08\u4ee5\u79d2\u4e3a\u5355\u4f4d\uff09\u3002\u5237\u65b0\u65f6\u95f4\u5728 Lightning Experience \u548c Salesforce \u79fb\u52a8\u5e94\u7528\u7a0b\u5e8f\u4e2d\u81ea\u52a8\u914d\u7f6e\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9ed8\u8ba4\u7f13\u5b58\u6301\u7eed\u65f6\u95f4\u53ef\u80fd\u4f1a\u968f\u7740\u5e73\u53f0\u7684\u4f18\u5316\u800c\u66f4\u6539\u3002\u5728\u8bbe\u8ba1 Lightning Web \u7ec4\u4ef6\u65f6\uff0c\u4e0d\u8981\u5047\u8bbe\u7f13\u5b58\u6301\u7eed\u65f6\u95f4\u3002\u5982\u679c\u7ec4\u4ef6\u77e5\u9053\u7f13\u5b58\u7684\u503c\u65e0\u6548\uff08\u4f8b\u5982\uff0c\u5f53\u57fa\u7840\u6570\u636e\u53d1\u751f\u66f4\u6539\u65f6\uff09\uff0c\u5b83\u53ef\u4ee5\u5411\u670d\u52a1\u5668\u67e5\u8be2\u66f4\u65b0\u7684\u6570\u636e\uff0c\u5e76\u4f7f\u7528 from \u5237\u65b0\u7f13\u5b58\u3002<code>refreshApex()<\/code><code>@salesforce\/apex<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63d0\u793a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">lwc-recipes\u00a0\u5b58\u50a8\u5e93\u4e2d\u7684\u7ec4\u4ef6\u8c03\u7528 .<code>ldsDeleteRecordrefreshApex()<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f3a\u5236\u8c03\u7528\u65b9\u6cd5\u65f6\u5237\u65b0\u7f13\u5b58<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5237\u65b0\u8fc7\u65f6\u7684 Apex \u6570\u636e\uff0c\u8bf7\u8c03\u7528 Apex \u65b9\u6cd5\uff0c\u7136\u540e\u8c03\u7528\u00a0notifyRecordUpdateAvailable\uff08recordIds\uff09 \u4ee5\u66f4\u65b0 Lightning \u6570\u636e\u670d\u52a1 \uff08LDS\uff09 \u7f13\u5b58\u3002Lightning \u6570\u636e\u670d\u52a1\u4e0d\u7ba1\u7406\u7531\u547d\u4ee4\u6027 Apex \u8c03\u7528\u9884\u7f6e\u7684\u6570\u636e\u3002\u8c03\u7528 Apex \u65b9\u6cd5\u540e\uff0c\u8c03\u7528\u4ee5\u5411 Lightning \u6570\u636e\u670d\u52a1\u53d1\u51fa\u67d0\u4e9b\u8bb0\u5f55\u5df2\u8fc7\u65f6\u7684\u4fe1\u53f7\uff0c\u5e76\u5237\u65b0\u7f13\u5b58\u4e2d\u7684\u8fd9\u4e9b\u8bb0\u5f55\u3002<code>notifyRecordUpdateAvailable(recordIds)<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { LightningElement, wire } from 'lwc';\nimport { getRecord, notifyRecordUpdateAvailable } from 'lightning\/uiRecordApi';\nimport apexUpdateRecord from '@salesforce\/apex\/Controller.apexUpdateRecord';\n\nexport default class Example extends LightningElement {\n    @api recordId;\n\n    \/\/ Wire a record\n    @wire(getRecord, { recordId: '$recordId', fields: ... })\n    record;\n\n    async handler() {\n      \/\/ Do something before the record is updated\n      showSpinner();\n\n      \/\/ Update the record via Apex\n      await apexUpdateRecord(this.recordId);\n\n      \/\/ Notify LDS that you've changed the record outside its mechanisms\n      \/\/ Await the Promise object returned by notifyRecordUpdateAvailable()\n      await notifyRecordUpdateAvailable(&#91;{recordId: this.recordId}]);\n      hideSpinner();\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528@wire\u65f6\u5237\u65b0\u7f13\u5b58<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5237\u65b0\u901a\u8fc7 Apex \u7f6e\u5907\u7684 Apex \u6570\u636e\uff0c\u8bf7\u8c03\u7528 \u3002\u8be5\u51fd\u6570\u4f7f\u7528\u7ed1\u5b9a\u5230 \u7684\u914d\u7f6e\u9884\u914d\u6570\u636e\u5e76\u66f4\u65b0\u7f13\u5b58\u3002<code>@wire<\/code><code>refreshApex()<\/code><code>@wire<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u5237\u65b0\u65f6\u4f7f\u7528\u7684\u53c2\u6570\u5fc5\u987b\u662f\u4ee5\u524d\u7531 Apex \u53d1\u51fa\u7684\u5bf9\u8c61\u3002<code>refreshApex()<\/code><code>@wire<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u65f6\uff0c\u60a8\u77e5\u9053\u7f13\u5b58\u5df2\u8fc7\u65f6\u3002\u5982\u679c\u7f13\u5b58\u5df2\u8fc7\u65f6\uff0c\u5219\u7ec4\u4ef6\u9700\u8981\u65b0\u6570\u636e\u3002\u82e5\u8981\u5728\u670d\u52a1\u5668\u4e2d\u67e5\u8be2\u66f4\u65b0\u7684\u6570\u636e\u5e76\u5237\u65b0\u7f13\u5b58\uff0c\u8bf7\u5bfc\u5165\u5e76\u8c03\u7528\u8be5\u51fd\u6570\u3002\u4ec5\u5728\u5fc5\u8981\u65f6\u8c03\u7528\uff0c\u56e0\u4e3a\u5b83\u4f1a\u5bfc\u81f4\u67e5\u8be2\u670d\u52a1\u5668\u7684\u7f51\u7edc\u884c\u7a0b\u3002<code>refreshApex()<\/code><code>refreshApex()<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u51fd\u6570\u8fd4\u56de\u4e00\u4e2a Promise\u3002\u89e3\u6790 Promise \u540e\uff0c\u7ebf\u8def\u4e2d\u7684\u6570\u636e\u662f\u6700\u65b0\u7684\u3002Apex \u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u4ec5\u5728 \u4e0a\u53ef\u7528\u3002\u5f53 Promise \u89e3\u6790\u65f6\uff0c\u6709\u65b0\u6570\u636e\uff0c\u4f46 Promise \u89e3\u6790\u5230\u7684\u5b9e\u9645\u503c\u662f\u6ca1\u6709\u610f\u4e49\u7684\u3002\u4f7f\u7528\u5757\u5904\u7406\u5237\u65b0\u7684\u6570\u636e\uff0c\u4f8b\u5982\u5728\u9875\u9762\u4e0a\u8bbe\u7f6e\u5c5e\u6027\u3002<code>refreshApex()<\/code><code>@wire<\/code><code>@wire<\/code><code>then()<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { refreshApex } from \"@salesforce\/apex\";\nrefreshApex(valueProvisionedByApexWireService);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5176\u4e2d \u662f\u7528 Apex \u6ce8\u91ca\u7684\u5c5e\u6027\uff0c\u6216\u8005\u5982\u679c\u6ce8\u91ca\u4e86\u51fd\u6570\uff0c\u5219\u4e3a\u6709\u7ebf\u51fd\u6570\u63a5\u6536\u7684\u53c2\u6570\u3002<code>valueProvisionedByApexWireService<\/code><code>@wire<\/code><code>\/\/ Example of refreshing data for a wired property \/\/ after you update data via an LDS-managed module (lightning\/uiRecordApi). import { updateRecord } from 'lightning\/uiRecordApi'; import { refreshApex } from '@salesforce\/apex'; import getOpptyOverAmount from '@salesforce\/apex\/OpptyController.getOpptyOverAmount; @wire(getOpptyOverAmount, { amount: '$amount' }) opptiesOverAmount; \/\/ Update the record using updateRecord(recordInput) \/\/ Refresh Apex data that the wire service provisioned handler() { updateRecord(recordInput).then(() =&gt; { refreshApex(this.opptiesOverAmount); }); }<\/code><code>\/\/ Example of refreshing data for a wired property \/\/ after you update data via imperative Apex. import { refreshApex } from '@salesforce\/apex'; import { notifyRecordUpdateAvailable } from 'lightning\/uiRecordApi'; import getOpptyOverAmount from '@salesforce\/apex\/OpptyController.getOpptyOverAmount; @wire(getOpptyOverAmount, { amount: '$amount' }) opptiesOverAmount; \/\/ Update the record in Apex, such as via a button click \/\/ Refresh Apex data that the wire service provisioned handler() { updateRecordApexMethod() .then(() =&gt; { refreshApex(this.opptiesOverAmount); notifyRecordUpdateAvailable(recordIds); \/\/ Refresh the Lightning Data Service cache }); }<\/code><code>\/\/Example of refreshing data for a wired function import { refreshApex } from '@salesforce\/apex'; import getActivityHistory from '@salesforce\/apex\/ActivityController.getActivityHistory; @wire(getActivityHistory, { accountId: '$recordId', max: '500' }) wiredGetActivityHistory(value) { \/\/ Hold on to the provisioned value so we can refresh it later. this.wiredActivities = value; \/\/ Destructure the provisioned value const { data, error } = value; if (data) { ... } else if (error) { ... } ... } handler() { refreshApex(this.wiredActivities); }<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u5237\u65b0\u6709\u7ebf\u5c5e\u6027\u7684\u7f13\u5b58<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u770b\u4e00\u4e2a\u4f8b\u5b50\u3002\u6b64\u7ec4\u4ef6\u663e\u793a\u8d85\u8fc7\u6307\u5b9a\u6570\u91cf\u7684\u5546\u673a\u5217\u8868\u3002\u7528\u6237\u53ef\u4ee5\u5355\u51fb\u4ee5\u5c06\u6240\u6709\u5546\u673a\u6807\u8bb0\u4e3a\u201c\u5df2\u8d62\u5f97\u201d\u3002\u5f53\u673a\u4f1a\u66f4\u65b0\u65f6\uff0c\u7f13\u5b58\u6570\u636e\u5c06\u53d8\u5f97\u8fc7\u65f6\u3002\u56e0\u6b64\uff0c\u5728\u4ee3\u7801\u66f4\u65b0\u5546\u673a\u540e\uff0c\u5b83\u4f1a\u8c03\u7528\u4ee5\u67e5\u8be2\u670d\u52a1\u5668\u4ee5\u83b7\u53d6\u66f4\u65b0\u7684\u6570\u636e\u5e76\u5237\u65b0\u7f13\u5b58\u3002<code>refreshApex()<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"426\" height=\"312\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_refresh.png\" alt=\"\" class=\"wp-image-3880\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_refresh.png 426w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_refresh-300x220.png 300w\" sizes=\"(max-width: 426px) 100vw, 426px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- opportunitiesOverAmount.html --&gt;\n&lt;template&gt;\n  &lt;!-- Display a list of opportunities --&gt;\n  &lt;p&gt;\n    List of opportunities over\n    &lt;lightning-formatted-number\n      value={amount}\n      format-style=\"currency\"\n    &gt;&lt;\/lightning-formatted-number&gt;\n  &lt;\/p&gt;\n  &lt;template lwc:if={opptiesOverAmount.data}&gt;\n    &lt;template for:each={opptiesOverAmount.data} for:item=\"oppty\" for:index=\"idx\"&gt;\n      &lt;div key={oppty.Id} class=\"slds-m-bottom_medium\"&gt;\n        &lt;p&gt;{idx}. {oppty.Name}&lt;\/p&gt;\n        &lt;p&gt;\n          &lt;lightning-formatted-number\n            value={oppty.Amount}\n            format-style=\"currency\"\n          &gt;&lt;\/lightning-formatted-number&gt;\n        &lt;\/p&gt;\n        &lt;p&gt;\n          &lt;lightning-formatted-date-time value={oppty.CloseDate}&gt;&lt;\/lightning-formatted-date-time&gt;\n        &lt;\/p&gt;\n        &lt;p&gt;&lt;lightning-badge label={oppty.StageName}&gt;&lt;\/lightning-badge&gt;&lt;\/p&gt;\n      &lt;\/div&gt;\n    &lt;\/template&gt;\n    &lt;!-- Click the button to change the opportunities. Requires the data to be refetched\n             and rerendered --&gt;\n    &lt;lightning-button label=\"Mark all as Closed Won\" onclick={handleClick}&gt;&lt;\/lightning-button&gt;\n  &lt;\/template&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u7ec4\u4ef6\u7684 JavaScript \u4ee3\u7801\u3002\u9996\u5148\uff0c\u5b83\u4ece \u5bfc\u5165 Apex \u65b9\u6cd5\u3002<code>&lt;c-opportunities-over-amount&gt;<\/code><code>refreshApex<\/code><code>@salesforce\/apex<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7136\u540e\uff0c\u5b83\u4f7f\u7528\u52a8\u6001\u503c \u8c03\u7528 Apex \u65b9\u6cd5\u3002\u6bcf\u5f53\u53d1\u751f\u66f4\u6539\u65f6\uff0c\u90fd\u4f1a\u91cd\u65b0\u8bf7\u6c42\u6570\u636e\u3002\u7cfb\u7edf\u4ece\u5ba2\u6237\u7aef\u7f13\u5b58\u6216\u670d\u52a1\u5668\u63d0\u4f9b\u6570\u636e\u3002<code>getOpptyOverAmount<\/code><code>amount<\/code><code>this.amount<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ opportunitiesOverAmount.js\nimport { LightningElement, api, wire } from \"lwc\";\nimport { refreshApex } from \"@salesforce\/apex\";\nimport getOpptyOverAmount from \"@salesforce\/apex\/OpptiesOverAmountApex.getOpptyOverAmount\";\nimport updateOpptyStage from \"@salesforce\/apex\/OpptiesOverAmountApex.updateOpptyStage\";\n\nexport default class OpportunitiesOverAmount extends LightningElement {\n  @api amount = 500000;\n\n  @wire(getOpptyOverAmount, { amount: \"$amount\" })\n  opptiesOverAmount;\n\n  handleClick(e) {\n    updateOpptyStage({\n      amount: this.amount,\n      stage: \"Closed Won\",\n    })\n      .then(() =&gt; {\n        refreshApex(this.opptiesOverAmount).then(() =&gt; {\n          \/\/ do something with the refreshed data in this.opptiesOverAmount\n        });\n      })\n      .catch((error) =&gt; {\n        this.message =\n          \"Error received: code\" + error.errorCode + \", \" + \"message \" + error.body.message;\n      });\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee3\u7801\u5728\u65b9\u6cd5\u4e2d\u8c03\u7528\u3002\u5c06 Closed Won \u66f4\u6539\u4e3a Closed Won \u4f1a\u5f71\u54cd\u5b57\u6bb5\uff0c\u8fd9\u610f\u5473\u7740\u6570\u636e\u5df2\u8fc7\u65f6\u3002\u5f53\u60a8\u5c06\u6765\u6709\u5173\u95ed\u65e5\u671f\u65f6\uff0c\u201c\u5173\u95ed\u65e5\u671f\u201d\u5b57\u6bb5\u5c06\u66f4\u6539\u4e3a\u4eca\u5929\u7684\u65e5\u671f\u3002<code>refreshApex()<\/code><code>handleClick<\/code><code>stage<\/code><code>CloseDate<\/code><code>@wire<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u544a\u77e5\u7cfb\u7edf\u6570\u636e\u5df2\u8fc7\u65f6\uff0c\u8bf7\u8c03\u7528 \u3002\u6709\u7ebf\u9002\u914d\u5668\u5c06\u5176\u7f13\u5b58\u6807\u8bb0\u4e3a\u8fc7\u65f6\uff0c\u91cd\u65b0\u67e5\u8be2\u670d\u52a1\u5668\u4ee5\u83b7\u53d6\u66f4\u65b0\u7684\u6570\u636e\uff0c\u66f4\u65b0\u5176\u7f13\u5b58\uff0c\u7136\u540e\u901a\u77e5\u5176\u8ba2\u9605\u8005\u3002\u53d1\u751f\u8fd9\u79cd\u60c5\u51b5\u65f6\uff0c\u7ec4\u4ef6\u7684\u5c5e\u6027\u4f1a\u66f4\u65b0\uff0c\u4ece\u800c\u89e6\u53d1\u4f7f\u7528\u65b0\u6570\u636e\u91cd\u65b0\u5448\u73b0\u3002\u6536\u76d8\u65e5\u671f\u73b0\u5728\u662f\uff08\u4eca\u5929\u7684\u65e5\u671f\uff09\uff0c\u673a\u4f1a\u9636\u6bb5\u73b0\u5728\u662f\u201cClosed Won\u201d\u3002<code>refreshApex()<\/code><code>this.opptiesOverAmount<\/code><code>July 18, 2019<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"426\" height=\"313\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_refresh_result.png\" alt=\"\" class=\"wp-image-3881\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_refresh_result.png 426w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_refresh_result-300x220.png 300w\" sizes=\"(max-width: 426px) 100vw, 426px\" \/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u7c7b\u5305\u542b\u8be5\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u68c0\u7d22\u8d85\u8fc7\u6307\u5b9a\u6570\u91cf\u7684\u673a\u4f1a\u5217\u8868\u3002\u5b83\u8fd8\u5305\u542b\u8be5\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u4f7f\u7528 DML \u64cd\u4f5c\u5c06\u8d85\u8fc7\u6307\u5b9a\u91d1\u989d\u7684\u5546\u673a\u9636\u6bb5\u66f4\u65b0\u4e3a\u201cClosed Won\u201d\u3002<code>OpptiesOverAmountApex<\/code><code>getOpptyOverAmount<\/code><code>updateOpptyStage<\/code><code>update<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class OpptiesOverAmountApex {\n    @AuraEnabled(cacheable=true)\n    public static List&lt;Opportunity&gt; getOpptyOverAmount(Decimal amount) {\n        return &#91;SELECT Id, Name, Amount, StageName, CloseDate FROM Opportunity WHERE Amount &gt; :amount];\n    }\n\n    @AuraEnabled\n    public static void updateOpptyStage(Decimal amount, String stage) {\n        for (List&lt;Opportunity&gt; oppts:\n            &#91;SELECT Id, Name, Amount, StageName, CloseDate FROM Opportunity WHERE Amount &gt; :amount]) {\n                for(Opportunity o : oppts) {\n                    o.StageName = stage;\n                }\n                update oppts;\n            }\n            return;\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u5237\u65b0\u6709\u7ebf\u51fd\u6570\u7684\u7f13\u5b58<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5237\u65b0\u6709\u7ebf\u51fd\u6570\uff0c\u8bf7\u5c06\u6709\u7ebf\u51fd\u6570\u63a5\u6536\u7684\u53c2\u6570\uff08\u5373\u6709\u7ebf\u503c\uff09\u4f20\u9012\u7ed9 \u3002\u5728\u6b64\u793a\u4f8b\u4ee3\u7801\u4e2d\uff0c\u6709\u7ebf\u51fd\u6570\u4e3a \u3002\u4fdd\u7559\u7ebf\u8def\u670d\u52a1\u63d0\u4f9b\u7684\u503c\u5e76\u5c06\u5176\u4f20\u9012\u7ed9 \u3002<code>refreshApex()<\/code><code>wiredGetActivityHistory(value)<\/code><code>refreshApex()<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u65b0\u51fd\u6570\u8fdb\u884c\u547d\u4ee4\u5f0f\u8c03\u7528\u3002\u8981\u8ddf\u8e2a\u5df2\u7f6e\u5907\u7684\u503c\uff0c\u8bf7\u5b9a\u4e49\u4e00\u4e2a\u65b0\u5c5e\u6027\uff0c\u5e76\u5728 \u4e2d\u4f7f\u7528\u5b83\u3002\u89e3\u6784\u9884\u7f6e\u7684\u503c\u4ee5\u8f7b\u677e\u63d0\u53d6 \u548c \u5bf9\u8c61\u3002<code>refreshApex()<\/code><code>wiredActivities<\/code><code>wiredGetActivityHistory(value)<\/code><code>data<\/code><code>error<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { LightningElement, api, wire } from 'lwc';\nimport { refreshApex } from '@salesforce\/apex';\nimport getActivityHistory from '@salesforce\/apex\/GalleryApexController.getActivityHistory';\n\nexport default class GalleryApexMaster extends LightningElement {\n    @api recordId;\n    wiredActivities;\n\n    @wire(getActivityHistory, { accountId: '$recordId', max: '500' })\n    wiredGetActivityHistory(value) {\n        \/\/ Hold on to the provisioned value so we can refresh it later.\n        this.wiredActivities = value; \/\/ track the provisioned value\n        const { data, error } = value; \/\/ destructure the provisioned value\n        if (data) { ... }\n        else if (error) { ... }\n        ...\n    }\n\n    handleLogACall() {\n        \/\/ Use the value to refresh wiredGetActivityHistory().\n        return refreshApex(this.wiredActivities);\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"import-objects-and-fields-from-@salesforceschema\">\u4ece\u4e2d\u5bfc\u5165\u5bf9\u8c61\u548c\u5b57\u6bb5<code>@salesforce\/schema<\/code><\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u60a8\u5bfc\u5165\u5bf9\u5bf9\u8c61\u548c\u5b57\u6bb5\u7684\u5f15\u7528\uff0cSalesforce \u4f1a\u9a8c\u8bc1\u5bf9\u8c61\u548c\u5b57\u6bb5\u662f\u5426\u5b58\u5728\uff08\u8fd9\u4e5f\u4f1a\u6355\u83b7\u62fc\u5199\u9519\u8bef\uff09\uff0c\u9632\u6b62\u5220\u9664\u5bf9\u8c61\u548c\u5b57\u6bb5\uff0c\u5e76\u5c06\u4efb\u4f55\u91cd\u547d\u540d\u7684\u5bf9\u8c61\u548c\u5b57\u6bb5\u7ea7\u8054\u5230\u7ec4\u4ef6\u7684\u6e90\u4ee3\u7801\u4e2d\u3002\u5b83\u8fd8\u786e\u4fdd\u4f9d\u8d56\u5bf9\u8c61\u548c\u5b57\u6bb5\u5305\u542b\u5728\u66f4\u6539\u96c6\u548c\u5305\u4e2d\u3002\u5bfc\u5165\u5bf9\u5bf9\u8c61\u548c\u5b57\u6bb5\u7684\u5f15\u7528\u53ef\u786e\u4fdd\u4ee3\u7801\u6b63\u5e38\u5de5\u4f5c\uff0c\u5373\u4f7f\u5bf9\u8c61\u548c\u5b57\u6bb5\u540d\u79f0\u53d1\u751f\u66f4\u6539\u4e5f\u662f\u5982\u6b64\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u7ec4\u4ef6\u901a\u8fc7 Apex \u7c7b\u83b7\u53d6\u5bf9\u8c61\u5e76\u4ece \u5bfc\u5165\u5bf9\u5bf9\u8c61\u7684\u5f15\u7528\uff0c\u5219\u8c03\u7528\u4ee5\u4ece\u5bf9\u8c61\u4e2d\u83b7\u53d6\u5b57\u6bb5\u503c\u3002<code>@salesforce\/schema<\/code><code>getSObjectValue()<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>getSObjectValue(sobject, fieldApiName);<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><code>{sobject}<\/code>&#8211; Apex \u65b9\u6cd5\u8fd4\u56de\u7684\u5bf9\u8c61\u3002<\/li>\n\n\n\n<li><code>{fieldApiName}<\/code>&#8211; \u5b57\u6bb5\u7684 API \u540d\u79f0\u3002\u8be5\u503c\u53ef\u4ee5\u662f\u5b57\u7b26\u4e32\uff0c\u4e5f\u53ef\u4ee5\u662f\u5bf9\u4ece \u5bfc\u5165\u7684\u5b57\u6bb5\u7684\u5f15\u7528\u3002\u60a8\u6700\u591a\u53ef\u4ee5\u6307\u5b9a 5 \u4e2a\u7ea7\u522b\u7684\u751f\u6210\u5b57\u6bb5\u3002\u4f8b\u5982\uff0c\u8fd4\u56de 4 \u7ea7\u751f\u6210\u5b57\u6bb5\u3002<code>@salesforce\/schema<\/code><code>Opportunity.Account.CreatedBy.LastModifiedById<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u8ba9\u6211\u4eec\u770b\u4e00\u4e0b\u00a0lwc-recipes\u00a0\u4e2d\u7684\u7ec4\u4ef6\u3002\u8be5\u7ec4\u4ef6\u4ece\u8fd4\u56de\u5355\u4e2a\u8054\u7cfb\u4eba\u7684 Apex \u65b9\u6cd5\u83b7\u53d6\u5176\u6570\u636e\u3002<code>apexStaticSchema<\/code><\/p>\n\n\n\n<figure class=\"wp-block-image size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"417\" height=\"134\" src=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_static_schema.png\" alt=\"\" class=\"wp-image-3882\" srcset=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_static_schema.png 417w, http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex_static_schema-300x96.png 300w\" sizes=\"(max-width: 417px) 100vw, 417px\" \/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ ContactController.cls\npublic with sharing class ContactController {\n    @AuraEnabled(cacheable=true)\n    public static Contact getSingleContact(){\n        return &#91;SELECT Id, Name, Title, Phone, Email, Picture__c FROM Contact LIMIT 1];\n    }\n\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">JavaScript \u4ece \u5bfc\u5165\u51fd\u6570\u548c\u65b9\u6cd5\u3002\u5b83\u4ece \u5bfc\u5165\u5bf9\u8054\u7cfb\u4eba\u5b57\u6bb5\u7684\u5f15\u7528\u3002<code>getSObjectValue<\/code><code>getSingleContact<\/code><code>@salesforce\/apex<\/code><code>@salesforce\/schema<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u65b9\u6cd5\u5df2\u8fde\u63a5\u5230\u5c5e\u6027\u3002\u6a21\u677f\u4e2d\u7684 \u3001 \u548c \u5c5e\u6027\u5177\u6709 getter\uff0c\u8fd9\u4e9b getter \u8c03\u7528\u4ee5\u4ece\u6307\u5b9a\u5b57\u6bb5\u4e2d\u63d0\u53d6\u503c\u3002<code>contact<\/code><code>name<\/code><code>title<\/code><code>email<\/code><code>getSObjectValue()<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ apexStaticSchema.js\nimport { LightningElement, wire } from \"lwc\";\nimport { getSObjectValue } from \"@salesforce\/apex\";\nimport getSingleContact from \"@salesforce\/apex\/ContactController.getSingleContact\";\n\nimport NAME_FIELD from \"@salesforce\/schema\/Contact.Name\";\nimport TITLE_FIELD from \"@salesforce\/schema\/Contact.Title\";\nimport EMAIL_FIELD from \"@salesforce\/schema\/Contact.Email\";\n\nexport default class ApexStaticSchema extends LightningElement {\n  @wire(getSingleContact) contact;\n\n  get name() {\n    return this.contact.data ? getSObjectValue(this.contact.data, NAME_FIELD) : \"\";\n  }\n  get title() {\n    return this.contact.data ? getSObjectValue(this.contact.data, TITLE_FIELD) : \"\";\n  }\n  get email() {\n    return this.contact.data ? getSObjectValue(this.contact.data, EMAIL_FIELD) : \"\";\n  }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- apexStaticSchema.html --&gt;\n&lt;template&gt;\n  &lt;lightning-card title=\"ApexStaticSchema\" icon-name=\"custom:custom63\"&gt;\n    &lt;template lwc:if={contact.data}&gt;\n      &lt;div class=\"slds-m-around_medium\"&gt;\n        &lt;p&gt;{name}&lt;\/p&gt;\n        &lt;p&gt;{title}&lt;\/p&gt;\n        &lt;p&gt;&lt;lightning-formatted-email value={email}&gt;&lt;\/lightning-formatted-email&gt;&lt;\/p&gt;\n      &lt;\/div&gt;\n    &lt;\/template&gt;\n    &lt;template lwc:elseif={contact.error}&gt;\n      &lt;c-error-panel errors={contact.error}&gt;&lt;\/c-error-panel&gt;\n    &lt;\/template&gt;\n  &lt;\/lightning-card&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"make-long-running-callouts-with-continuations\">\u4f7f\u7528\u5ef6\u7eed\u8fdb\u884c\u957f\u65f6\u95f4\u7684\u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 Apex \u4e2d\u7684\u7c7b\u5411\u5916\u90e8 Web \u670d\u52a1\u53d1\u51fa\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u8bf7\u6c42\u3002\u5728\u56de\u8c03\u65b9\u6cd5\u4e2d\u5904\u7406\u54cd\u5e94\u3002\u5ef6\u7eed\u662f\u7ba1\u7406\u5ba3\u4f20\u4fe1\u606f\u7684\u9996\u9009\u65b9\u5f0f\uff0c\u56e0\u4e3a\u5b83\u4eec\u53ef\u4ee5\u5927\u5e45\u6539\u5584\u7528\u6237\u4f53\u9a8c\u3002<code>Continuation<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u5ef6\u7eed\u6709\u4e00\u4e9b\u4f18\u70b9\uff0c\u5305\u62ec\u80fd\u591f\u5e76\u884c\u8fdb\u884c\u6807\u6ce8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6846\u67b6\u5728\u5c06\u64cd\u4f5c\u53d1\u9001\u5230\u670d\u52a1\u5668\u4e4b\u524d\u5bf9\u64cd\u4f5c\u8fdb\u884c\u6392\u961f\u3002\u5728\u7f16\u5199\u4ee3\u7801\u65f6\uff0c\u6b64\u673a\u5236\u5728\u5f88\u5927\u7a0b\u5ea6\u4e0a\u5bf9\u60a8\u662f\u900f\u660e\u7684\uff0c\u4f46\u5b83\u4f7f\u6846\u67b6\u80fd\u591f\u901a\u8fc7\u5c06\u591a\u4e2a\u64cd\u4f5c\u6279\u5904\u7406\u5230\u4e00\u4e2a\u8bf7\u6c42 \uff08XHR\uff09 \u4e2d\u6765\u6700\u5927\u7a0b\u5ea6\u5730\u51cf\u5c11\u7f51\u7edc\u6d41\u91cf\u3002\u52a8\u4f5c\u7684\u6279\u5904\u7406\u4e5f\u79f0\u4e3a\u68da\u8f66\uff0c\u7c7b\u4f3c\u4e8e\u5c06\u68da\u8f66\u8026\u5408\u5728\u4e00\u8d77\u7684\u706b\u8f66\u3002\u7531\u4e8e\u5ef6\u7eed\u53ef\u4ee5\u662f\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u8bf7\u6c42\uff0c\u56e0\u6b64\u8be5\u6846\u67b6\u5b9e\u8d28\u4e0a\u5c06\u5ef6\u7eed\u89c6\u4e3a\u540e\u53f0\u64cd\u4f5c\u3002\u5ef6\u7eed\u4e0d\u4f1a\u4e0e\u5176\u4ed6\u8bf7\u6c42\u7ed1\u5b9a\uff0c\u56e0\u6b64\u5b83\u4eec\u5728\u8fd0\u884c\u65f6\u4e0d\u4f1a\u963b\u6b62\u5176\u4ed6\u64cd\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528\u5ef6\u7eed\u53d1\u51fa\u7684\u5f02\u6b65\u6807\u6ce8\u4e0d\u8ba1\u5165\u6301\u7eed\u65f6\u95f4\u8d85\u8fc7 5 \u79d2\u7684\u540c\u6b65\u8bf7\u6c42\u7684 Apex \u9650\u5236\u3002\u81ea 20 \u5e74\u51ac\u5b63\u4ee5\u6765\uff0c\u6240\u6709\u6807\u6ce8\u90fd\u88ab\u6392\u9664\u5728\u957f\u671f\u8fd0\u884c\u7684\u8bf7\u6c42\u9650\u5236\u4e4b\u5916\uff0c\u56e0\u6b64\u4e0e\u5e38\u89c4\u6807\u6ce8\u76f8\u6bd4\uff0c\u5ef6\u7eed\u4e0d\u518d\u4e3a\u4f7f\u7528\u9650\u5236\u63d0\u4f9b\u4f18\u52bf\u3002\u4f46\u662f\uff0c\u7531\u4e8e\u6539\u5584\u4e86\u7528\u6237\u4f53\u9a8c\uff0c\u6211\u4eec\u5efa\u8bae\u4f7f\u7528\u5ef6\u7eed\u6765\u7ba1\u7406\u5ba3\u4f20\u4fe1\u606f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"work-with-a-continuation-in-an-apex-class\">\u5728 Apex \u7c7b\u4e2d\u4f7f\u7528\u5ef6\u7eed<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u4f7f\u7528 Apex \u7c7b\u4e2d\u7684\u5ef6\u7eed\uff0c\u8bf7\u4f7f\u7528 Apex \u5bf9\u8c61\u3002<code>Continuation<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5148\u51b3\u6761\u4ef6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8c03\u7528\u5916\u90e8\u670d\u52a1\u4e4b\u524d\uff0c\u60a8\u5fc5\u987b\u5c06\u8fdc\u7a0b\u7ad9\u70b9\u6dfb\u52a0\u5230 Salesforce \u7528\u6237\u754c\u9762\u4e2d\u7684\u6388\u6743\u8fdc\u7a0b\u7ad9\u70b9\u5217\u8868\u4e2d\u3002\u5728\u201c<strong>\u8bbe\u7f6e<\/strong>\u201d\u7684\u201c<strong>\u5feb\u901f\u67e5\u627e<\/strong>\u201d\u6846\u4e2d\uff0c\u8f93\u5165 \u3002\u9009\u62e9<strong>\u201c<\/strong>\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u201d\uff0c\u7136\u540e\u5355\u51fb\u201c<strong>\u65b0\u5efa\u8fdc\u7a0b\u7ad9\u70b9<\/strong>\u201d\u3002\u6dfb\u52a0\u4e0e\u4e0b\u9762\u7684 Apex \u7c7b\u5ef6\u7eed\u793a\u4f8b\u4e2d\u5bf9\u5e94\u7684\u6807\u6ce8 URL\u3002<code>Remote Site Settings<\/code><code>LONG_RUNNING_SERVICE_URL<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6807\u6ce8\u5c06\u547d\u540d\u51ed\u636e\u6307\u5b9a\u4e3a\u7ec8\u7ed3\u70b9\uff0c\u5219\u65e0\u9700\u914d\u7f6e\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u3002\u547d\u540d\u51ed\u636e\u5728\u4e00\u4e2a\u5b9a\u4e49\u4e2d\u6307\u5b9a\u6807\u6ce8\u7ec8\u7ed3\u70b9\u7684 URL \u53ca\u5176\u6240\u9700\u7684\u8eab\u4efd\u9a8c\u8bc1\u53c2\u6570\u3002\u5728\u4ee3\u7801\u4e2d\uff0c\u6307\u5b9a\u547d\u540d\u51ed\u636e URL\uff0c\u800c\u4e0d\u662f\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u670d\u52a1 URL\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528 Continuation \u5bf9\u8c61<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u82e5\u8981\u8fdb\u884c\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u6807\u6ce8\uff0c\u8bf7\u5b9a\u4e49\u4e00\u4e2a\u8fd4\u56de\u5bf9\u8c61\u7684 Apex \u65b9\u6cd5\u3002\uff08\u5148\u4e0d\u7528\u62c5\u5fc3\u6ce8\u89e3\u7684\u5c5e\u6027\u3002\u6211\u4eec\u5f88\u5feb\u5c31\u4f1a\u89e3\u91ca\u3002<code>Continuation<\/code><code>@AuraEnabled<\/code><code>@AuraEnabled(continuation=true cacheable=true) public static Object startRequest() { \/\/ Create continuation. Argument is timeout in seconds. Continuation con = new Continuation(40); \/\/ more to come here return con; }<\/code><\/li>\n\n\n\n<li>\u5728\u5bf9\u8c61\u7684\u5c5e\u6027\u4e2d\u8bbe\u7f6e\u6807\u6ce8\u5b8c\u6210\u540e\u8981\u8c03\u7528\u7684 Apex \u56de\u8c03\u65b9\u6cd5\u3002\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u56de\u8c03\u65b9\u6cd5\u4e3a \u3002\u56de\u8c03\u65b9\u6cd5\u5fc5\u987b\u4f4d\u4e8e\u540c\u4e00 Apex \u7c7b\u4e2d\u3002<code>continuationMethod<\/code><code>Continuation<\/code><code>processResponse<\/code><code>con.continuationMethod='processResponse';<\/code><\/li>\n\n\n\n<li>\u901a\u8fc7\u5411\u6807\u6ce8\u5bf9\u8c61\u6dfb\u52a0\u5bf9\u8c61\u6765\u8bbe\u7f6e\u6807\u6ce8\u7684\u7aef\u70b9\u3002\u5355\u4e2a\u5bf9\u8c61\u6700\u591a\u53ef\u4ee5\u5305\u542b\u4e09\u4e2a\u6ce8\u89e3\u3002\u6bcf\u4e2a\u6807\u6ce8\u90fd\u5fc5\u987b\u5728\u5b89\u88c5\u7a0b\u5e8f\u4e2d\u5b9a\u4e49\u4e00\u4e2a\u8fdc\u7a0b\u7ad9\u70b9\u6216\u547d\u540d\u51ed\u636e\u3002<code>HttpRequest<\/code><code>Continuation<\/code><code>Continuation<\/code><code>HttpRequest req = new HttpRequest(); req.setMethod('GET'); req.setEndpoint(LONG_RUNNING_SERVICE_URL); con.addHttpRequest(req);<\/code><\/li>\n\n\n\n<li>\u5728\u5bf9\u8c61\u7684\u5c5e\u6027\u4e2d\u8bbe\u7f6e\u8981\u4f20\u9012\u7ed9\u56de\u8c03\u65b9\u6cd5\u7684\u6570\u636e\u3002\u8be5\u5c5e\u6027\u5177\u6709\u7c7b\u578b\uff0c\u56e0\u6b64\u53ef\u4ee5\u4f20\u5165 Apex \u4e2d\u652f\u6301\u7684\u4efb\u4f55\u6570\u636e\u7c7b\u578b\u3002<code>state<\/code><code>Continuation<\/code><code>state<\/code><code>Object<\/code><code>con.state='Hello, World!';<\/code><\/li>\n\n\n\n<li>\u5728 Apex \u56de\u8c03\u4e2d\u7f16\u5199\u903b\u8f91\u4ee3\u7801\u3002\u5f53\u5bf9\u8c61\u4e2d\u8bbe\u7f6e\u7684\u6240\u6709\u6807\u6ce8\u90fd\u5b8c\u6210\u540e\uff0c\u5c06\u8c03\u7528 Apex \u56de\u8c03\u65b9\u6cd5 \u3002\u56de\u8c03\u65b9\u6cd5\u6709\u4e24\u4e2a\u53ef\u4ee5\u8bbf\u95ee\u7684\u53c2\u6570\u3002<code>Continuation<\/code><code>processResponse<\/code><code>public static Object processResponse(List&lt;String&gt; labels, Object state)<\/code>\n<ol class=\"wp-block-list\">\n<li><code>labels<\/code>&#8211; \u6807\u7b7e\u5217\u8868\uff0c\u5bf9\u5e94\u4e8e\u5ef6\u7eed\u4e2d\u7684\u6bcf\u4e2a\u8bf7\u6c42\u3002\u8fd9\u4e9b\u6807\u7b7e\u662f\u81ea\u52a8\u521b\u5efa\u7684\u3002<\/li>\n\n\n\n<li><code>state<\/code>&#8211; \u5728\u5bf9\u8c61\u7684\u5c5e\u6027\u4e2d\u8bbe\u7f6e\u7684\u72b6\u6001\u3002<code>state<\/code><code>Continuation<\/code><\/li>\n<\/ol>\n<\/li>\n\n\n\n<li>\u83b7\u53d6\u5ef6\u7eed\u4e2d\u6bcf\u4e2a\u8bf7\u6c42\u7684\u54cd\u5e94\u3002\u4f8b\u5982\uff1a<code>HttpResponse response = Continuation.getResponse(labels[0]);<\/code><\/li>\n\n\n\n<li>\u5c06\u7ed3\u679c\u8fd4\u56de\u5230\u7ec4\u4ef6\u7684 JavaScript \u6587\u4ef6\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u793a\u4f8b\uff1a\u5177\u6709\u5ef6\u7eed\u7684 Apex \u7c7b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u5b8c\u6574\u7684 Apex \u7c7b\uff0c\u5b83\u5c06\u6240\u6709\u524d\u9762\u7684\u6b65\u9aa4\u8054\u7cfb\u5728\u4e00\u8d77\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class SampleContinuationClass {\n    \/\/ Callout endpoint as a named credential URL\n    \/\/ or, as shown here, as the long-running service URL\n    private static final String LONG_RUNNING_SERVICE_URL =\n        '&lt;insert your callout URL here&gt;';\n\n    \/\/ Action method\n    @AuraEnabled(continuation=true cacheable=true)\n    public static Object startRequest() {\n      \/\/ Create continuation. Argument is timeout in seconds.\n      Continuation con = new Continuation(40);\n      \/\/ Set callback method\n      con.continuationMethod='processResponse';\n      \/\/ Set state\n      con.state='Hello, World!';\n      \/\/ Create callout request\n      HttpRequest req = new HttpRequest();\n      req.setMethod('GET');\n      req.setEndpoint(LONG_RUNNING_SERVICE_URL);\n      \/\/ Add callout request to continuation\n      con.addHttpRequest(req);\n      \/\/ Return the continuation\n      return con;\n    }\n\n    \/\/ Callback method\n    @AuraEnabled(cacheable=true)\n    public static Object processResponse(List&lt;String&gt; labels, Object state) {\n      \/\/ Get the response by using the unique label\n      HttpResponse response = Continuation.getResponse(labels&#91;0]);\n      \/\/ Set the result variable\n      String result = response.getBody();\n      return result;\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"@auraenabled-annotations-for-continuations\"><code>@AuraEnabled<\/code>\u5ef6\u7eed\u7684\u6ce8\u91ca<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5ef6\u7eed\u4f7f\u7528 Apex \u4ee3\u7801\u7684\u6ce8\u91ca\u3002\u4ee5\u4e0b\u662f\u4f7f\u7528\u89c4\u5219\u3002<code>@AuraEnabled<\/code><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><code>@AuraEnabled(continuation=true)<\/code><\/strong>\u8fd4\u56de\u5ef6\u7eed\u7684 Apex \u63a7\u5236\u5668\u65b9\u6cd5\u5fc5\u987b\u7528 \u6ce8\u91ca\u3002<code>@AuraEnabled(continuation=true)<\/code><\/li>\n\n\n\n<li><strong><code>@AuraEnabled(continuation=true cacheable=true)<\/code><\/strong>\u82e5\u8981\u7f13\u5b58\u5ef6\u7eed\u64cd\u4f5c\u7684\u7ed3\u679c\uff0c\u8bf7\u5728 Apex \u56de\u8c03\u65b9\u6cd5\u7684\u6ce8\u91ca\u4e0a\u8bbe\u7f6e\u3002<code>cacheable=true<\/code>\u6ce8\u610f\u4e4b\u95f4\u6709\u4e00\u4e2a\u7a7a\u683c\uff0c<strong>\u800c\u4e0d\u662f\u9017\u53f7<\/strong>\u3002<code>continuation=true cacheable=true<\/code><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u7f13\u5b58\u6ce8\u610f\u4e8b\u9879<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6700\u4f73\u505a\u6cd5\u662f\u8bbe\u7f6e\u5ef6\u7eed\u94fe\u4e2d\u6d89\u53ca\u7684\u6240\u6709\u65b9\u6cd5\uff0c\u5305\u62ec\u8fd4\u56de\u5bf9\u8c61\u7684\u65b9\u6cd5\u3002<code>cacheable=true<\/code><code>Continuation<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6b64\u793a\u4f8b\u4e2d\uff0c\u8fd4\u56de\u5ef6\u7eed \u7684 Apex \u65b9\u6cd5\u548c\u56de\u8c03 \uff0c\u90fd\u5305\u542b\u5728\u5176\u6279\u6ce8\u4e2d\u3002<code>startRequest()<\/code><code>processResponse()<\/code><code>cacheable=true<\/code><code>@AuraEnabled<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Action method\n@AuraEnabled(continuation=true cacheable=true)\npublic static Object startRequest() { }\n\n\/\/ Callback method\n@AuraEnabled(cacheable=true)\npublic static Object processResponse(List&lt;String&gt; labels,\n  Object state) { }<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u53ef\u7f13\u5b58\u8bbe\u7f6e\u884c\u4e3a<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u8868\u603b\u7ed3\u4e86 \u4e2d\u5c5e\u6027\u7684\u4e0d\u540c\u8bbe\u7f6e\u7684\u884c\u4e3a\u3002<code>cacheable<\/code><code>@AuraEnabled<\/code><\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u8fd4\u56de Continuation \u5bf9\u8c61\u7684\u65b9\u6cd5 \u6ce8\u91ca<code>cacheable=true<\/code><\/th><th>\u56de\u8c03\u65b9\u6cd5\u6ce8\u89e3<code>cacheable=true<\/code><\/th><th>\u6709\u6548\uff1f<\/th><th>\u53ef\u4ee5\u4f7f\u7528 \uff1f<code>@wire<\/code><\/th><th>\u64cd\u4f5c\u54cd\u5e94\u662f\u5426\u7f13\u5b58\u5728\u5ba2\u6237\u7aef\u4e0a\uff1f<\/th><\/tr><\/thead><tbody><tr><td>\u662f\u7684<\/td><td>\u662f\u7684<\/td><td>\u662f\u7684<\/td><td>\u662f\u7684<\/td><td>\u662f\u7684<\/td><\/tr><tr><td>\u662f\u7684<\/td><td>\u4e0d<\/td><td>\u5426\uff08\u5f15\u53d1\u5f02\u5e38\uff09<\/td><td>\u4e0d\u9002\u7528<\/td><td>\u4e0d\u9002\u7528<\/td><\/tr><tr><td>\u4e0d<\/td><td>\u662f\u7684<\/td><td>\u662f\u7684<\/td><td>\u5426\uff08\u6240\u6709\u65b9\u6cd5\u90fd\u5fc5\u987b\u5177\u6709<code>cacheable=true<\/code>)<\/td><td>\u4e0d<\/td><\/tr><tr><td>\u4e0d<\/td><td>\u4e0d<\/td><td>\u662f\u7684<\/td><td>\u4e0d<\/td><td>\u4e0d<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"continuation-example\">\u5ef6\u7eed\u793a\u4f8b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u4e00\u4e2a\u7ec4\u4ef6\u7684\u6807\u8bb0\uff0c\u8be5\u7ec4\u4ef6\u5728\u5355\u51fb\u6309\u94ae\u540e\u8c03\u7528\u7ebf\u8def\u670d\u52a1\u7684\u5ef6\u7eed\u548c\u547d\u4ee4\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;!-- continuationCmp.html --&gt;\n&lt;template&gt;\n  &lt;lightning-button label=\"Call Continuation\" onclick={callContinuation}&gt; &lt;\/lightning-button&gt;\n  &lt;div&gt;@wire(startRequest) result: {formattedWireResult}&lt;\/div&gt;\n  &lt;div&gt;Imperative result: {formattedImperativeResult}&lt;\/div&gt;\n&lt;\/template&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">HTML \u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u7528\u4e8e\u89e6\u53d1\u5bf9\u5ef6\u7eed\u7684\u547d\u4ee4\u6027\u8c03\u7528\u3002\u5f53\u6211\u4eec\u63a5\u4e0b\u6765\u67e5\u770b JavaScript \u6587\u4ef6\u65f6\uff0c\u6211\u4eec\u4f1a\u770b\u5230\u66f4\u591a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u662f\u7ec4\u4ef6\u7684 JavaScript \u6587\u4ef6\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import { LightningElement, track, wire } from \"lwc\";\nimport startRequest from \"@salesforce\/apexContinuation\/SampleContinuationClass.startRequest\";\nexport default class ContinuationComponent extends LightningElement {\n  @track imperativeContinuation = {};\n\n  \/\/ Using wire service\n  @wire(startRequest)\n  wiredContinuation;\n\n  get formattedWireResult() {\n    return JSON.stringify(this.wiredContinuation);\n  }\n\n  \/\/ Imperative Call\n  callContinuation() {\n    startRequest()\n      .then((result) =&gt; {\n        this.imperativeContinuation = result;\n      })\n      .catch((error) =&gt; {\n        this.imperativeContinuation = error;\n      });\n  }\n\n  get formattedImperativeResult() {\n    return JSON.stringify(this.imperativeContinuation);\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u4ee3\u7801\u4f7f\u7528\u65b0\u7684\u5bfc\u5165\u8bed\u6cd5\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import startRequest from \"@salesforce\/apexContinuation\/SampleContinuationClass.startRequest\";<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64 import \u8bed\u53e5\u544a\u8bc9\u6846\u67b6\uff0c\u6211\u4eec\u6b63\u5728\u8c03\u7528\u4e00\u4e2a\u53ef\u4ee5\u8fd4\u56de\u5ef6\u7eed\u7684 Apex \u65b9\u6cd5\u3002\u5982\u679c Apex \u65b9\u6cd5\u8fd4\u56de\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5219\u5fc5\u987b\u4f7f\u7528 \u6279\u6ce8\u8be5\u65b9\u6cd5\u3002<code>startRequest<\/code><code>Continuation<\/code><code>@AuraEnabled(continuation=true)<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u7ec4\u4ef6\u4f7f\u7528\u7ebf\u8def\u670d\u52a1\u8c03\u7528 Apex \u65b9\u6cd5\u3002\u7ebf\u8def\u670d\u52a1\u5c06\u63a7\u5236\u6d41\u59d4\u6258\u7ed9 Lightning Web \u7ec4\u4ef6\u5f15\u64ce\u3002\u5728\u6267\u884c\u5ef6\u7eed\u540e\uff0c\u5f53\u7535\u7f06\u9002\u914d\u5668\u4e2d\u7684\u6570\u636e\u53d8\u5f97\u53ef\u7528\u65f6\uff0c\u6a21\u677f\u5c06\u663e\u793a\u7ed3\u679c\u3002\u60a8\u53ef\u4ee5\u4f7f\u7528\u7ebf\u8def\u670d\u52a1\uff0c\u56e0\u4e3a\u5728 Apex \u7c7b\u4e2d\u8fdb\u884c\u4e86\u6ce8\u91ca\u3002<code>startRequest<\/code><code>startRequest()<\/code><code>@AuraEnabled(cacheable=true)<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u5ef6\u7eed\u4f1a\u53d1\u51fa\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u8bf7\u6c42\uff0c\u56e0\u6b64\u60a8\u53ef\u80fd\u66f4\u613f\u610f\u901a\u8fc7\u53d1\u51fa\u547d\u4ee4\u6027\u8c03\u7528\u6765\u63a7\u5236\u5ef6\u7eed\u6267\u884c\u7684\u5f00\u59cb\u65f6\u95f4\uff0c\u800c\u4e0d\u662f\u4f7f\u7528\u7ebf\u8def\u670d\u52a1\u3002\u6b64\u7ec4\u4ef6\u4f7f\u7528\u6709\u7ebf\u670d\u52a1\u548c\u547d\u4ee4\u6027\u8c03\u7528\u3002\u6709\u7ebf\u670d\u52a1\u8c03\u7528\u5ef6\u7eed\u5e76\u7f13\u5b58\u7ed3\u679c\u3002\u5f53\u60a8\u5355\u51fb\u8be5\u6309\u94ae\u5bf9\u540c\u4e00 Apex \u65b9\u6cd5\u8fdb\u884c\u547d\u4ee4\u6027\u8c03\u7528\u65f6\uff0c\u7f13\u5b58\u7684\u7ed3\u679c\u5c06\u8fd4\u56de\u5e76\u663e\u793a\u5728\u6a21\u677f\u4e2d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"continuation-limits\">\u5ef6\u7eed\u9650\u5236<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u7531\u4e8e\u5ef6\u7eed\u53ef\u80fd\u5bfc\u81f4\u591a\u4e2a\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u64cd\u4f5c\uff0c\u56e0\u6b64\u5b83\u4eec\u7684\u4f7f\u7528\u5b58\u5728\u4e00\u4e9b\u9650\u5236\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u300aApex \u5f00\u53d1\u4eba\u5458\u6307\u5357\u300b\u4e2d\u5217\u51fa\u4e86\u5728\u00a0Apex \u4e2d\u4f7f\u7528\u5ef6\u7eed\u7684\u9650\u5236\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u4e00\u4e9b\u7279\u5b9a\u4e8e Lightning Web \u7ec4\u4ef6\u4f7f\u7528\u7684\u9650\u5236\u3002\u6bcf\u4e2a\u5ef6\u7eed\u6700\u591a 3 \u4e2a\u6807\u6ce8<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5355\u4e2a\u5bf9\u8c61\u6700\u591a\u53ef\u4ee5\u5305\u542b\u4e09\u4e2a\u6ce8\u89e3\u3002<code>Continuation<\/code>\u8fde\u7eed\u64cd\u4f5c\u7684\u4e32\u884c\u5904\u7406<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u6846\u67b6\u4ece\u5ba2\u6237\u7aef\u4e32\u884c\u5904\u7406\u5305\u542b\u5ef6\u7eed\u7684\u64cd\u4f5c\u3002\u5728\u8fdb\u884c\u4e0b\u4e00\u6b21\u5ef6\u7eed\u8c03\u7528\u4e4b\u524d\uff0c\u5fc5\u987b\u5b8c\u6210\u4e0a\u4e00\u6b21\u5ef6\u7eed\u8c03\u7528\u3002\u5728\u4efb\u4f55\u65f6\u5019\uff0c\u5ba2\u6237\u7aef\u4e0a\u53ea\u80fd\u6709\u4e00\u4e2a\u6b63\u5728\u8fdb\u884c\u7684\u5ef6\u7eed\u3002DML \u64cd\u4f5c\u9650\u5236<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd4\u56de\u5bf9\u8c61\u7684 Apex \u65b9\u6cd5\u4e0d\u80fd\u6267\u884c\u4efb\u4f55\u6570\u636e\u64cd\u4f5c\u8bed\u8a00 \uff08DML\uff09 \u64cd\u4f5c\u3002DML \u8bed\u53e5\u5728 Salesforce \u4e2d\u63d2\u5165\u3001\u66f4\u65b0\u3001\u5408\u5e76\u3001\u5220\u9664\u548c\u6062\u590d\u6570\u636e\u3002\u5982\u679c\u5728\u5ef6\u7eed\u65b9\u6cd5\u4e2d\u6267\u884c\u4e86\u4efb\u4f55 DML\uff0c\u5219\u5ef6\u7eed\u6267\u884c\u4e0d\u4f1a\u7ee7\u7eed\uff0c\u4e8b\u52a1\u5c06\u56de\u6eda\uff0c\u5e76\u8fd4\u56de\u9519\u8bef\u3002<code>Continuation<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u5728 Apex \u56de\u8c03\u65b9\u6cd5\u4e2d\u6267\u884c DML \u64cd\u4f5c\u4ee5\u5ef6\u7eed\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"secure-apex-classes\">\u4fdd\u62a4 Apex \u7c7b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cApex \u5728\u7cfb\u7edf\u6a21\u5f0f\u4e0b\u8fd0\u884c\uff0c\u8fd9\u610f\u5473\u7740\u5b83\u4ee5\u5927\u5e45\u63d0\u5347\u7684\u6743\u9650\u8fd0\u884c\uff0c\u5c31\u50cf\u7528\u6237\u62e5\u6709\u5927\u591a\u6570\u6743\u9650\u4ee5\u53ca\u6388\u4e88\u7684\u6240\u6709\u5b57\u6bb5\u548c\u5bf9\u8c61\u7ea7\u8bbf\u95ee\u6743\u9650\u4e00\u6837\u3002\u7531\u4e8e\u8fd9\u4e9b\u5b89\u5168\u5c42\u4e0d\u50cf\u5728 Salesforce UI \u4e2d\u90a3\u6837\u5f3a\u5236\u6267\u884c\uff0c\u56e0\u6b64\u60a8\u5fc5\u987b\u7f16\u5199\u4ee3\u7801\u6765\u5f3a\u5236\u6267\u884c\u5b83\u4eec\u3002\u5426\u5219\uff0c\u60a8\u7684\u7ec4\u4ef6\u53ef\u80fd\u4f1a\u65e0\u610f\u4e2d\u66b4\u9732\u654f\u611f\u6570\u636e\uff0c\u800c\u8fd9\u4e9b\u6570\u636e\u901a\u5e38\u4f1a\u5728 Salesforce UI \u4e2d\u5bf9\u7528\u6237\u9690\u85cf\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4f7f\u7528 Salesforce \u8bb0\u5f55\uff0c\u6211\u4eec\u5efa\u8bae\u4f7f\u7528 Lightning \u6570\u636e\u670d\u52a1\uff0c\u5b83\u4e3a\u60a8\u5904\u7406\u5171\u4eab\u89c4\u5219\u3001CRUD \u548c\u5b57\u6bb5\u7ea7\u5b89\u5168\u6027\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6388\u4e88\u7528\u6237\u5bf9 Apex \u7c7b\u7684\u8bbf\u95ee\u6743\u9650<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ec5\u5f53\u7528\u6237\u7684\u914d\u7f6e\u6587\u4ef6\u6216\u5206\u914d\u7684\u6743\u9650\u96c6\u5141\u8bb8\u8bbf\u95ee Apex \u7c7b\u65f6\uff0c\u7ecf\u8fc7\u8eab\u4efd\u9a8c\u8bc1\u7684\u7528\u6237\u6216\u6765\u5bbe\u7528\u6237\u624d\u80fd\u8bbf\u95ee Apex \u65b9\u6cd5\u3002<code>@AuraEnabled<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u5173\u914d\u7f6e\u7528\u6237\u914d\u7f6e\u6587\u4ef6\u6216\u6743\u9650\u96c6\u5bf9 Apex \u7c7b\u7684\u8bbf\u95ee\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u300aApex \u5f00\u53d1\u4eba\u5458\u6307\u5357\u300b\u4e2d\u7684\u7c7b\u5b89\u5168\u6027\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f3a\u5236\u6267\u884c\u5171\u4eab\u89c4\u5219<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u58f0\u660e\u7c7b\u65f6\uff0c\u6700\u4f73\u505a\u6cd5\u662f\u6307\u5b9a\u5728\u7ec4\u4ef6\u4f7f\u7528 Apex \u63a7\u5236\u5668\u65f6\u5f3a\u5236\u6267\u884c\u5171\u4eab\u89c4\u5219\u3002<code>with sharing<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class SharingClass {\n    \/\/ Code here\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u672a\u663e\u5f0f\u8bbe\u7f6e \u6216 \u5b9a\u4e49\u7684 Apex \u7c7b\uff0c\u6216\u8005\u4f7f\u7528 \u5b9a\u4e49\u7684 Apex \u7c7b\u4f7f\u7528\u9ed8\u8ba4\u503c\u6216\u9690\u5f0f\u503c\u3002\u4f46\u662f\uff0cApex \u7c7b\u4e0d\u4f1a\u663e\u5f0f\u8bbe\u7f6e\u6216\u7ee7\u627f\u5176\u8fd0\u884c\u4e0a\u4e0b\u6587\u4e2d\u7684\u503c\u3002\u56e0\u6b64\uff0c\u5f53\u8bbe\u7f6e\u5176\u4e2d\u4e00\u4e2a\u5173\u952e\u5b57\u7684\u7c7b\u8c03\u7528\u6ca1\u6709\u663e\u5f0f\u5171\u4eab\u884c\u4e3a\u7684\u7c7b\u65f6\uff0c\u5b83\u5c06\u4e0e\u8c03\u7528\u7c7b\u7684\u5171\u4eab\u884c\u4e3a\u4e00\u8d77\u64cd\u4f5c\u3002\u8981\u786e\u4fdd\u60a8\u7684\u73ed\u7ea7\u5f3a\u5236\u6267\u884c\u5171\u4eab\u89c4\u5219\uff0c\u8bf7\u5c06 .<code>@AuraEnabled<\/code><code>with sharing<\/code><code>without sharing<\/code><code>inherited sharing<\/code><code>with sharing<\/code><code>with sharing<\/code><code>without sharing<\/code><code>with sharing<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5173\u952e\u5b57\u5f3a\u5236\u6267\u884c\u8bb0\u5f55\u7ea7\u5b89\u5168\u6027\u3002\u5b83\u4e0d\u5f3a\u5236\u5b9e\u65bd\u5bf9\u8c61\u7ea7\u548c\u5b57\u6bb5\u7ea7\u5b89\u5168\u6027\u3002\u60a8\u5fc5\u987b\u5728 Apex \u7c7b\u4e2d\u5206\u522b\u624b\u52a8\u5f3a\u5236\u5b9e\u65bd\u5bf9\u8c61\u7ea7\u548c\u5b57\u6bb5\u7ea7\u5b89\u5168\u6027\u3002<code>with sharing<\/code><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f3a\u5236\u6267\u884c\u5bf9\u8c61\u548c\u5b57\u6bb5\u6743\u9650\uff08CRUD \u548c FLS\uff09<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u51e0\u79cd\u66ff\u4ee3\u65b9\u6cd5\u53ef\u4ee5\u5728 Apex \u4ee3\u7801\u4e2d\u5f3a\u5236\u6267\u884c\u5bf9\u8c61\u7ea7\u548c\u5b57\u6bb5\u7ea7\u6743\u9650\u3002\u6700\u7b80\u5355\u7684\u5f3a\u5236\u6267\u884c\u65b9\u5f0f<code>WITH SECURITY_ENFORCED<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u5f3a\u5236\u6267\u884c\u5bf9\u8c61\u7ea7\u548c\u5b57\u6bb5\u7ea7\u6743\u9650\uff0c\u8bf7\u5728 Apex \u4ee3\u7801\u4e2d\u5c06\u8be5\u5b50\u53e5\u7528\u4e8e\u67e5\u8be2\uff0c\u5305\u62ec\u5b50\u67e5\u8be2\u548c\u8de8\u5bf9\u8c61\u5173\u7cfb\u3002<code>WITH SECURITY_ENFORCED<\/code><code>SOQL SELECT<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u4f60\u5728\u5f00\u53d1\u5b89\u5168\u4ee3\u7801\u65b9\u9762\u7ecf\u9a8c\u6700\u5c11\uff0c\u5e76\u4e14\u5bf9\u4e8e\u4e0d\u9700\u8981\u5bf9\u6743\u9650\u9519\u8bef\u8fdb\u884c\u6b63\u5e38\u964d\u7ea7\u7684\u5e94\u7528\u7a0b\u5e8f\uff0c\u5219\u8be5\u5b50\u53e5\u662f\u7406\u60f3\u7684\u9009\u62e9\u3002<code>WITH SECURITY_ENFORCED<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u4f7f\u7528\u4e0d\u5b89\u5168\u7684\u65b9\u6cd5 \u67e5\u8be2\u81ea\u5b9a\u4e49\u652f\u51fa\u5bf9\u8c61\u4e0a\u7684\u5b57\u6bb5\u3002\u4e0d\u8981\u4f7f\u7528\u8fd9\u4e2a\u7c7b\uff01<code>get_UNSAFE_Expenses()<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ This class is an anti-pattern.\npublic with sharing class UnsafeExpenseController {\n    \/\/ ns refers to namespace; leave out ns__ if not needed\n    \/\/ This method is vulnerable because it doesn't enforce FLS.\n    @AuraEnabled\n    public static List&lt;ns__Expense__c&gt; get_UNSAFE_Expenses() {\n        return &#91;SELECT Id, Name, ns__Amount__c, ns__Client__c, ns__Date__c,\n            ns__Reimbursed__c, CreatedDate FROM ns__Expense__c];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u4e00\u4e2a\u793a\u4f8b\u4f7f\u7528\u5b89\u5168\u65b9\u6cd5 \uff0c\u8be5\u65b9\u6cd5\u4f7f\u7528\u5b50\u53e5\u5f3a\u5236\u6267\u884c\u5bf9\u8c61\u7ea7\u548c\u5b57\u6bb5\u7ea7\u6743\u9650\u3002\u4f7f\u7528\u6b64\u7c7b\u4ee3\u66ff .<code>getExpenses()<\/code><code>WITH SECURITY_ENFORCED<\/code><code>UnsafeExpenseController<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ExpenseController {\n    \/\/ This method is recommended because it enforces FLS.\n    @AuraEnabled\n    public static List&lt;ns__Expense__c&gt; getExpenses() {\n    \/\/ Query the object safely\n    return &#91;SELECT Id, Name, ns__Amount__c, ns__Client__c, ns__Date__c,\n            ns__Reimbursed__c, CreatedDate\n             FROM ns__Expense__c WITH SECURITY_ENFORCED];\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u00a0Apex \u5f00\u53d1\u4eba\u5458\u6307\u5357\u3002\u4f18\u96c5\u964d\u89e3<code>stripInaccessible()<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u66f4\u4f18\u96c5\u5730\u964d\u7ea7\u6743\u9650\u9519\u8bef\uff0c\u8bf7\u4f7f\u7528\u8be5\u65b9\u6cd5\u5f3a\u5236\u5b9e\u65bd\u5b57\u6bb5\u7ea7\u548c\u5bf9\u8c61\u7ea7\u6570\u636e\u4fdd\u62a4\u3002\u6b64\u65b9\u6cd5\u4ece\u7528\u6237\u65e0\u6cd5\u8bbf\u95ee\u7684\u67e5\u8be2\u548c\u5b50\u67e5\u8be2\u7ed3\u679c\u4e2d\u5220\u9664\u5b57\u6bb5\u548c\u5173\u7cfb\u5b57\u6bb5\u3002\u5982\u679c\u9700\u8981\uff0c\u60a8\u53ef\u4ee5\u67e5\u770b\u662f\u5426\u6709\u4efb\u4f55\u5b57\u6bb5\u88ab\u5265\u79bb\uff0c\u5e76\u629b\u51fa\u5e26\u6709\u81ea\u5b9a\u4e49\u9519\u8bef\u6d88\u606f\u7684\u5b57\u6bb5\u3002<code>stripInaccessible()<\/code><code>AuraHandledException<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u8fd8\u53ef\u4ee5\u4f7f\u7528\u8be5\u65b9\u6cd5\u5728 DML \u64cd\u4f5c\u4e4b\u524d\u5220\u9664\u65e0\u6cd5\u8bbf\u95ee\u7684 sObject \u5b57\u6bb5\uff0c\u4ee5\u907f\u514d\u5f02\u5e38\u5e76\u6e05\u7406\u5df2\u4ece\u4e0d\u53d7\u4fe1\u4efb\u7684\u6e90\u53cd\u5e8f\u5217\u5316\u7684 sObject\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u5c06\u66f4\u65b0\u4e3a\u4f7f\u7528 SOQL \u5b50\u53e5\u3002\u7ed3\u679c\u662f\u76f8\u540c\u7684\uff0c\u4f46\u8ba9\u60a8\u6709\u673a\u4f1a\u5728\u4f7f\u7528 \u65f6\u6b63\u5e38\u964d\u7ea7\uff0c\u800c\u4e0d\u662f\u56e0\u8bbf\u95ee\u51b2\u7a81\u800c\u5931\u8d25\u3002<code>ExpenseController<\/code><code>stripInaccessible()<\/code><code>WITH SECURITY_ENFORCED<\/code><code>stripInaccessible()<\/code><code>WITH SECURITY_ENFORCED<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ExpenseControllerStripped {\n\n    @AuraEnabled\n    public static List&lt;ns__Expense__c&gt; getExpenses() {\n        \/\/ Query the object but don't use WITH SECURITY_ENFORCED\n        List&lt;ns__Expense__c&gt; expenses =\n            &#91;SELECT Id, Name, ns__Amount__c, ns__Client__c, ns__Date__c,\n                ns__Reimbursed__c, CreatedDate\n                 FROM ns__Expense__c];\n\n         \/\/ Strip fields that are not readable\n         SObjectAccessDecision decision = Security.stripInaccessible(\n               AccessType.READABLE,\n               expenses);\n\n         \/\/ Throw an exception if any data was stripped\n         if (!decision.getModifiedIndexes().isEmpty()) {\n            throw new AuraHandledException('Data was stripped');\n         }\n\n         return expenses;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6709\u5173\u66f4\u591a\u8be6\u7ec6\u4fe1\u606f\u548c\u793a\u4f8b\uff0c\u8bf7\u53c2\u9605\u00a0Apex \u5f00\u53d1\u4eba\u5458\u6307\u5357\u3002\u9057\u7559\u4ee3\u7801 using \u548c methods<code>DescribeSObjectResultDescribeFieldResult<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5b50\u53e5\u548c\u65b9\u6cd5\u53ef\u7528\u4e4b\u524d\uff0c\u5f3a\u5236\u6267\u884c\u5bf9\u8c61\u548c\u5b57\u6bb5\u6743\u9650\u7684\u552f\u4e00\u65b9\u6cd5\u662f\u901a\u8fc7\u8c03\u7528 and \u65b9\u6cd5\u6765\u68c0\u67e5\u5f53\u524d\u7528\u6237\u7684\u8bbf\u95ee\u6743\u9650\u7ea7\u522b\u3002\u7136\u540e\uff0c\u5982\u679c\u7528\u6237\u5177\u6709\u5fc5\u8981\u7684\u6743\u9650\uff0c\u5219\u6267\u884c\u7279\u5b9a\u7684 DML \u64cd\u4f5c\u6216\u67e5\u8be2\u3002<code>WITH SECURITY_ENFORCED<\/code><code>stripInaccessible()<\/code><code>Schema.DescribeSObjectResult<\/code><code>Schema.DescribeFieldResult<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u8c03\u7528 \u3001 \u6216 \u65b9\u6cd5\u5206\u522b\u9a8c\u8bc1\u5f53\u524d\u7528\u6237\u662f\u5426\u5177\u6709\u5bf9 \u7684\u8bfb\u53d6\u3001\u521b\u5efa\u6216\u66f4\u65b0\u8bbf\u95ee\u6743\u9650\u3002\u540c\u6837\uff0c\u516c\u5f00\u8bbf\u95ee\u63a7\u5236\u65b9\u6cd5\uff0c\u60a8\u53ef\u4ee5\u8c03\u7528\u8fd9\u4e9b\u65b9\u6cd5\u6765\u68c0\u67e5\u5f53\u524d\u7528\u6237\u5bf9\u5b57\u6bb5\u7684\u8bfb\u53d6\u3001\u521b\u5efa\u6216\u66f4\u65b0\u8bbf\u95ee\u6743\u9650\u3002<code>isAccessible<\/code><code>isCreateable<\/code><code>isUpdateable<\/code><code>Schema.DescribeSObjectResult<\/code><code>sObject<\/code><code>Schema.DescribeFieldResult<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u4f7f\u7528 describe result \u65b9\u6cd5\u3002\u6b64\u65b9\u6cd5\u9700\u8981\u66f4\u591a\u7684\u6837\u677f\u4ee3\u7801\u884c\uff0c\u56e0\u6b64\u6211\u4eec\u5efa\u8bae\u6539\u7528\u5b50\u53e5\u6216\u65b9\u6cd5\u3002<code>WITH SECURITY_ENFORCED<\/code><code>stripInaccessible()<\/code><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ExpenseControllerLegacy {\n    @AuraEnabled\n    public static List&lt;ns__Expense__c&gt; getExpenses() {\n        String &#91;] expenseAccessFields = new String &#91;] {'Id',\n                                                       'Name',\n                                                       'ns__Amount__c',\n                                                       'ns__Client__c',\n                                                       'ns__Date__c',\n                                                       'ns__Reimbursed__c',\n                                                       'CreatedDate'\n                                                       };\n\n\n    \/\/ Obtain the field name\/token map for the Expense object\n    Map&lt;String,Schema.SObjectField&gt; m = Schema.SObjectType.ns__Expense__c.fields.getMap();\n\n    for (String fieldToCheck : expenseAccessFields) {\n\n        \/\/ Call getDescribe to check if the user has access to view field\n        if (!m.get(fieldToCheck).getDescribe().isAccessible()) {\n\n            \/\/ Pass error to client\n            throw new System.NoAccessException();\n        }\n    }\n\n    \/\/ Query the object safely\n    return &#91;SELECT Id, Name, ns__Amount__c, ns__Client__c, ns__Date__c,\n            ns__Reimbursed__c, CreatedDate FROM ns__Expense__c];\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Lightning Web \u7ec4\u4ef6\u53ef\u4ee5\u4ece Apex \u7c7b\u5bfc\u5165\u65b9\u6cd5\u3002\u5bfc\u5165\u7684\u65b9\u6cd5\u662f\u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u8c03\u7528\u7684\u51fd\u6570\u3002@wire<\/p>\n<p>\u5728\u4f7f\u7528 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528\u57fa\u672c Lightning \u7ec4\u4ef6\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\u3002<\/p>\n","protected":false},"author":1,"featured_media":3873,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[233],"tags":[251],"class_list":["post-3872","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-lightning-web-","tag--apex-"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u8c03\u7528 Apex \u65b9\u6cd5 - \u767d\u767d\u968f\u7b14<\/title>\n<meta name=\"description\" content=\"Lightning Web \u7ec4\u4ef6\u53ef\u4ee5\u4ece Apex \u7c7b\u5bfc\u5165\u65b9\u6cd5\u3002\u5bfc\u5165\u7684\u65b9\u6cd5\u662f\u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u8c03\u7528\u7684\u51fd\u6570\u3002@wire\u5728\u4f7f\u7528 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528\u57fa\u672c Lightning \u7ec4\u4ef6\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\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=3872\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u8c03\u7528 Apex \u65b9\u6cd5 - \u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"og:description\" content=\"Lightning Web \u7ec4\u4ef6\u53ef\u4ee5\u4ece Apex \u7c7b\u5bfc\u5165\u65b9\u6cd5\u3002\u5bfc\u5165\u7684\u65b9\u6cd5\u662f\u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u8c03\u7528\u7684\u51fd\u6570\u3002@wire\u5728\u4f7f\u7528 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528\u57fa\u672c Lightning \u7ec4\u4ef6\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\u3002\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.ponybai.com\/?p=3872\" \/>\n<meta property=\"og:site_name\" content=\"\u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"article:published_time\" content=\"2024-01-17T08:29:17+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-02T08:58:00+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1013\" \/>\n\t<meta property=\"og:image:height\" content=\"91\" \/>\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=3872#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3872\"},\"author\":{\"name\":\"ponybai\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"headline\":\"\u8c03\u7528 Apex \u65b9\u6cd5\",\"datePublished\":\"2024-01-17T08:29:17+00:00\",\"dateModified\":\"2023-12-02T08:58:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3872\"},\"wordCount\":341,\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"keywords\":[\"\u8c03\u7528 Apex \u65b9\u6cd5\"],\"articleSection\":[\"Lightning Web \u7ec4\u4ef6\u5f00\u53d1\u4eba\u5458\u6307\u5357\"],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3872\",\"url\":\"http:\/\/www.ponybai.com\/?p=3872\",\"name\":\"\u8c03\u7528 Apex \u65b9\u6cd5 - \u767d\u767d\u968f\u7b14\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/#website\"},\"datePublished\":\"2024-01-17T08:29:17+00:00\",\"dateModified\":\"2023-12-02T08:58:00+00:00\",\"description\":\"Lightning Web \u7ec4\u4ef6\u53ef\u4ee5\u4ece Apex \u7c7b\u5bfc\u5165\u65b9\u6cd5\u3002\u5bfc\u5165\u7684\u65b9\u6cd5\u662f\u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u8c03\u7528\u7684\u51fd\u6570\u3002@wire\u5728\u4f7f\u7528 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528\u57fa\u672c Lightning \u7ec4\u4ef6\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\u3002\",\"breadcrumb\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3872#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.ponybai.com\/?p=3872\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3872#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/www.ponybai.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u8c03\u7528 Apex \u65b9\u6cd5\"}]},{\"@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":"\u8c03\u7528 Apex \u65b9\u6cd5 - \u767d\u767d\u968f\u7b14","description":"Lightning Web \u7ec4\u4ef6\u53ef\u4ee5\u4ece Apex \u7c7b\u5bfc\u5165\u65b9\u6cd5\u3002\u5bfc\u5165\u7684\u65b9\u6cd5\u662f\u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u8c03\u7528\u7684\u51fd\u6570\u3002@wire\u5728\u4f7f\u7528 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528\u57fa\u672c Lightning \u7ec4\u4ef6\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\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=3872","og_locale":"zh_CN","og_type":"article","og_title":"\u8c03\u7528 Apex \u65b9\u6cd5 - \u767d\u767d\u968f\u7b14","og_description":"Lightning Web \u7ec4\u4ef6\u53ef\u4ee5\u4ece Apex \u7c7b\u5bfc\u5165\u65b9\u6cd5\u3002\u5bfc\u5165\u7684\u65b9\u6cd5\u662f\u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u8c03\u7528\u7684\u51fd\u6570\u3002@wire\u5728\u4f7f\u7528 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528\u57fa\u672c Lightning \u7ec4\u4ef6\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\u3002","og_url":"http:\/\/www.ponybai.com\/?p=3872","og_site_name":"\u767d\u767d\u968f\u7b14","article_published_time":"2024-01-17T08:29:17+00:00","article_modified_time":"2023-12-02T08:58:00+00:00","og_image":[{"width":1013,"height":91,"url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/12\/apex.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=3872#article","isPartOf":{"@id":"http:\/\/www.ponybai.com\/?p=3872"},"author":{"name":"ponybai","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"headline":"\u8c03\u7528 Apex \u65b9\u6cd5","datePublished":"2024-01-17T08:29:17+00:00","dateModified":"2023-12-02T08:58:00+00:00","mainEntityOfPage":{"@id":"http:\/\/www.ponybai.com\/?p=3872"},"wordCount":341,"publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"keywords":["\u8c03\u7528 Apex \u65b9\u6cd5"],"articleSection":["Lightning Web \u7ec4\u4ef6\u5f00\u53d1\u4eba\u5458\u6307\u5357"],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/www.ponybai.com\/?p=3872","url":"http:\/\/www.ponybai.com\/?p=3872","name":"\u8c03\u7528 Apex \u65b9\u6cd5 - \u767d\u767d\u968f\u7b14","isPartOf":{"@id":"http:\/\/www.ponybai.com\/#website"},"datePublished":"2024-01-17T08:29:17+00:00","dateModified":"2023-12-02T08:58:00+00:00","description":"Lightning Web \u7ec4\u4ef6\u53ef\u4ee5\u4ece Apex \u7c7b\u5bfc\u5165\u65b9\u6cd5\u3002\u5bfc\u5165\u7684\u65b9\u6cd5\u662f\u7ec4\u4ef6\u53ef\u4ee5\u901a\u8fc7\u6216\u547d\u4ee4\u6027\u8c03\u7528\u7684\u51fd\u6570\u3002@wire\u5728\u4f7f\u7528 Apex \u65b9\u6cd5\u4e4b\u524d\uff0c\u8bf7\u786e\u4fdd\u6ca1\u6709\u66f4\u7b80\u5355\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u6570\u636e\uff0c\u4f8b\u5982\uff0c\u4f7f\u7528\u57fa\u672c Lightning \u7ec4\u4ef6\u3002\u8bf7\u53c2\u9605\u6570\u636e\u6307\u5357\u3002","breadcrumb":{"@id":"http:\/\/www.ponybai.com\/?p=3872#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.ponybai.com\/?p=3872"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.ponybai.com\/?p=3872#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/www.ponybai.com\/"},{"@type":"ListItem","position":2,"name":"\u8c03\u7528 Apex \u65b9\u6cd5"}]},{"@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\/3872","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=3872"}],"version-history":[{"count":1,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3872\/revisions"}],"predecessor-version":[{"id":3883,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3872\/revisions\/3883"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/media\/3873"}],"wp:attachment":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3872"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3872"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3872"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}