{"id":3757,"date":"2023-12-24T21:29:40","date_gmt":"2023-12-24T13:29:40","guid":{"rendered":"http:\/\/www.ponybai.com\/?p=3757"},"modified":"2023-11-27T21:32:42","modified_gmt":"2023-11-27T13:32:42","slug":"%e9%9b%86%e6%88%90%e5%92%8c-apex-%e5%ae%9e%e7%94%a8%e7%a8%8b%e5%ba%8f","status":"publish","type":"post","link":"http:\/\/www.ponybai.com\/?p=3757","title":{"rendered":"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Apex \u5141\u8bb8\u60a8\u4f7f\u7528\u6807\u6ce8\u4e0e\u5916\u90e8 SOAP \u548c REST Web \u670d\u52a1\u96c6\u6210\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u7528\u4e8e JSON\u3001XML\u3001\u6570\u636e\u5b89\u5168\u548c\u7f16\u7801\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u901a\u7528\u5b9e\u7528\u7a0b\u5e8f \u5bf9\u4e8e\u5e26\u6709\u6587\u672c\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e5f\u63d0\u4f9b\u4e86\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u4f7f\u7528 Apex \u8c03\u7528\u6807\u6ce8<\/strong><\/li>\n\n\n\n<li>JSON \u652f\u6301 Apex \u4e2d\u7684 JavaScript \u5bf9\u8c61\u8868\u793a\u6cd5 \uff08JSON\uff09\u00a0<strong>\u652f\u6301<\/strong><br>\u5c06 Apex \u5bf9\u8c61\u5e8f\u5217\u5316\u4e3a JSON \u683c\u5f0f\uff0c\u5e76\u5bf9\u5e8f\u5217\u5316\u7684 JSON \u5185\u5bb9\u8fdb\u884c\u53cd\u5e8f\u5217\u5316\u3002<\/li>\n\n\n\n<li>XML\u00a0<strong>Support<\/strong><br>Apex \u63d0\u4f9b\u5b9e\u7528\u7a0b\u5e8f\u7c7b\uff0c\u8fd9\u4e9b\u7c7b\u652f\u6301\u4f7f\u7528\u6d41\u548c DOM \u521b\u5efa\u548c\u89e3\u6790 XML \u5185\u5bb9\u3002<\/li>\n\n\n\n<li>\u4fdd\u62a4<strong>\u6570\u636e<\/strong><br>\u53ef\u4ee5\u4f7f\u7528\u7c7b\u63d0\u4f9b\u7684\u65b9\u6cd5\u4fdd\u62a4\u6570\u636e\u3002<samp>Crypto<\/samp><\/li>\n\n\n\n<li><strong>\u5bf9\u6570\u636e<\/strong><br>\u8fdb\u884c\u7f16\u7801 \u53ef\u4ee5\u4f7f\u7528\u7c7b\u63d0\u4f9b\u7684\u65b9\u6cd5\u5bf9 URL \u8fdb\u884c\u7f16\u7801\u548c\u89e3\u7801\uff0c\u5e76\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u4e3a\u5341\u516d\u8fdb\u5236\u683c\u5f0f\u3002<samp>EncodingUtil<\/samp><\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u6a21\u5f0f\u548c\u5339\u914d<\/strong>\u5668 Apex \u63d0\u4f9b\u4e86\u6a21\u5f0f\u548c\u5339\u914d\u5668<br>\uff0c\u4f7f\u60a8\u80fd\u591f\u4f7f\u7528\u6b63\u5219\u8868\u8fbe\u5f0f\u641c\u7d22\u6587\u672c\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528 Apex \u8c03\u7528\u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u501f\u52a9 Apex \u6807\u6ce8\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u5c06 Apex \u4e0e\u5916\u90e8\u670d\u52a1\u7d27\u5bc6\u96c6\u6210 \u8c03\u7528\u5916\u90e8 Web \u670d\u52a1\u6216\u4ece Apex \u4ee3\u7801\u53d1\u9001 HTTP \u8bf7\u6c42\uff0c\u7136\u540e\u63a5\u6536 \u54cd\u5e94\u3002Apex \u63d0\u4f9b\u4e0e\u5229\u7528 SOAP \u548c WSDL \u6216 HTTP \u7684 Web \u670d\u52a1\u7684\u96c6\u6210 \u670d\u52a1\uff08RESTful \u670d\u52a1\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4efb\u4f55 Apex \u6807\u6ce8\u53ef\u4ee5\u8c03\u7528\u5916\u90e8\u7ad9\u70b9\u4e4b\u524d\uff0c\u8be5\u7ad9\u70b9 \u5fc5\u987b\u5728\u201c\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u201d\u9875\u4e2d\u6ce8\u518c\uff0c\u5426\u5219\u6807\u6ce8\u5c06\u5931\u8d25\u3002Salesforce\u7684 \u9632\u6b62\u8c03\u7528\u672a\u7ecf\u6388\u6743\u7684\u7f51\u7edc\u5730\u5740\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6807\u6ce8\u6307\u5b9a\u4e86\u547d\u540d \u51ed\u636e\u4f5c\u4e3a\u7ec8\u7ed3\u70b9\uff0c\u5219\u65e0\u9700\u914d\u7f6e\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u3002\u4e00\u4e2a\u547d\u540d\u7684 credential \u6307\u5b9a\u6807\u6ce8\u7aef\u70b9\u7684 URL \u53ca\u5176\u6240\u9700\u7684\u8eab\u4efd\u9a8c\u8bc1 \u4e00\u4e2a\u5b9a\u4e49\u4e2d\u7684\u53c2\u6570\u3002\u82e5\u8981\u8bbe\u7f6e\u547d\u540d\u51ed\u636e\uff0c\u8bf7\u53c2\u9605\u201c\u5b9a\u4e49\u547d\u540d\u51ed\u636e\u201d \u5728 Salesforce \u5e2e\u52a9\u4e2d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u8be6\u7ec6\u4e86\u89e3\u6807\u6ce8\u7c7b\u578b\uff0c\u8bf7\u53c2\u9605\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SOAP \u670d\u52a1\uff1a\u4ece WSDL \u6587\u6863\u5b9a\u4e49\u7c7b<\/li>\n\n\n\n<li>\u8c03\u7528 HTTP \u6807\u6ce8<\/li>\n\n\n\n<li>\u5f02\u6b65 \u957f\u65f6\u95f4\u8fd0\u884c\u7684\u8bf7\u6c42\u7684\u6807\u6ce8<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u63d0\u793a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6807\u6ce8\u4f7f Apex \u80fd\u591f\u8c03\u7528\u5916\u90e8 Web \u6216 HTTP \u670d\u52a1\u3002Apex\u00a0Web \u670d\u52a1\u5141\u8bb8\u5916\u90e8\u5e94\u7528\u7a0b\u5e8f\u8c03\u7528 Apex \u65b9\u6cd5 \u901a\u8fc7 Web \u670d\u52a1\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u6dfb\u52a0\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e<\/li>\n\n\n\n<li>\u547d\u540d\u51ed\u636e\u4f5c\u4e3a\u6807\u6ce8\u7aef\u70b9 \u547d\u540d\u51ed\u636e\u5728\u4e00\u4e2a\u5b9a\u4e49\u4e2d\u6307\u5b9a\u6807\u6ce8\u7aef\u70b9<br>\u7684 URL \u53ca\u5176\u6240\u9700\u7684\u8eab\u4efd\u9a8c\u8bc1\u53c2\u6570\u3002Salesforce \u7ba1\u7406\u5c06\u6307\u5b9a\u547d\u540d\u51ed\u636e\u4f5c\u4e3a\u6807\u6ce8\u7aef\u70b9\u7684 Apex \u6807\u6ce8\u7684\u6240\u6709\u8eab\u4efd\u9a8c\u8bc1\uff0c\u4ee5\u4fbf\u60a8\u7684\u4ee3\u7801\u4e0d\u5fc5\u8fd9\u6837\u505a\u3002\u5bf9\u4e8e\u547d\u540d\u51ed\u636e\u4e2d\u5b9a\u4e49\u7684\u7ad9\u70b9\uff0c\u8fd8\u53ef\u4ee5\u8df3\u8fc7\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\uff0c\u5426\u5219\uff0c\u5916\u90e8\u7ad9\u70b9\u7684\u6807\u6ce8\u5c06\u9700\u8981\u8fd9\u4e9b\u8bbe\u7f6e\u3002<\/li>\n\n\n\n<li>SOAP \u670d\u52a1\uff1a\u4ece WSDL \u6587\u6863\u5b9a\u4e49\u7c7b<\/li>\n\n\n\n<li>\u8c03\u7528 HTTP \u6807\u6ce8<\/li>\n\n\n\n<li>\u4f7f\u7528\u8bc1\u4e66<\/li>\n\n\n\n<li>\u6807\u6ce8\u9650\u5236\u548c\u5c40\u9650\u6027<\/li>\n\n\n\n<li>\u4f7f\u7528\u5ef6\u7eed\u521b\u5efa\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u6807\u6ce8<br>\u4f7f\u7528\u5f02\u6b65\u6807\u6ce8\u4ece Visualforce \u9875\u9762\u6216 Lightning \u7ec4\u4ef6\u5411\u5916\u90e8 Web \u670d\u52a1\u53d1\u51fa\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u8bf7\u6c42\uff0c\u5e76\u5728\u56de\u8c03\u65b9\u6cd5\u4e2d\u5904\u7406\u54cd\u5e94\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u6dfb\u52a0\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\"><a><\/a>\u5728\u4efb\u4f55 Apex \u6807\u6ce8\u53ef\u4ee5\u8c03\u7528\u5916\u90e8\u7ad9\u70b9\u4e4b\u524d\uff0c\u8be5\u7ad9\u70b9 \u5fc5\u987b\u5728\u201c\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u201d\u9875\u4e2d\u6ce8\u518c\uff0c\u5426\u5219\u6807\u6ce8\u5c06\u5931\u8d25\u3002Salesforce\u7684 \u9632\u6b62\u8c03\u7528\u672a\u7ecf\u6388\u6743\u7684\u7f51\u7edc\u5730\u5740\u3002<\/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\u6307\u5b9a\u547d\u540d\u51ed\u636e\u4f5c\u4e3a\u7ec8\u7ed3\u70b9\uff0c\u5219\u65e0\u9700\u914d\u7f6e \u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u3002\u547d\u540d\u51ed\u636e\u6307\u5b9a\u6807\u6ce8\u7aef\u70b9\u7684 URL \u53ca\u5176 \u4e00\u4e2a\u5b9a\u4e49\u4e2d\u6240\u9700\u7684\u8eab\u4efd\u9a8c\u8bc1\u53c2\u6570\u3002\u82e5\u8981\u8bbe\u7f6e\u547d\u540d\u51ed\u636e\uff0c\u8bf7\u53c2\u9605\u201c\u5b9a\u4e49\u201d \u547d\u540d\u51ed\u636e\u201d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u6dfb\u52a0\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<a><\/a><\/p>\n\n\n\n<ol class=\"wp-block-list\" id=\"remote_site_instructions\">\n<li>\u5728\u201c\u8bbe\u7f6e\u201d\u4e2d\uff0c\u8f93\u5165\u201c\u5feb\u901f\u201d \u201c\u67e5\u627e\u201d\u6846\uff0c\u7136\u540e\u9009\u62e9<strong>\u201c\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e<\/strong>\u201d\u3002<kbd>Remote Site Settings<\/kbd><\/li>\n\n\n\n<li>\u5355\u51fb<strong>\u201c\u65b0\u5efa\u8fdc\u7a0b\u7ad9\u70b9<\/strong>\u201d\u3002<\/li>\n\n\n\n<li>\u8f93\u5165\u201c\u8fdc\u7a0b\u7ad9\u70b9\u540d\u79f0\u201d\u7684\u63cf\u8ff0\u6027\u672f\u8bed\u3002<\/li>\n\n\n\n<li>\u8f93\u5165\u8fdc\u7a0b\u7ad9\u70b9\u7684 URL\u3002<\/li>\n\n\n\n<li>\uff08\u53ef\u9009\uff09\u8f93\u5165\u7ad9\u70b9\u7684\u63cf\u8ff0\u3002<\/li>\n\n\n\n<li>\u70b9\u51fb<strong>\u4fdd\u5b58<\/strong>\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u63d0\u793a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u4e86\u83b7\u5f97\u6700\u4f73\u6027\u80fd\uff0c\u8bf7\u9a8c\u8bc1\u8fdc\u7a0b HTTPS \u52a0\u5bc6\u7ad9\u70b9\u662f\u5426\u5177\u6709 OCSP \uff08\u8054\u673a\u8bc1\u4e66\u72b6\u6001\u534f\u8bae\uff09\u88c5\u8ba2\u5df2\u6253\u5f00\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f5c\u4e3a\u6807\u6ce8\u7aef\u70b9\u7684\u547d\u540d\u51ed\u636e<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u547d\u540d\u51ed\u636e\u6307\u5b9a\u6807\u6ce8\u7aef\u70b9\u7684 URL \u53ca\u5176\u6240\u9700\u7684 URL \u4e00\u4e2a\u5b9a\u4e49\u4e2d\u7684\u8eab\u4efd\u9a8c\u8bc1\u53c2\u6570\u3002Salesforce \u7ba1\u7406 Apex \u7684\u6240\u6709\u8eab\u4efd\u9a8c\u8bc1 \u5c06\u547d\u540d\u51ed\u636e\u6307\u5b9a\u4e3a\u6807\u6ce8\u7ec8\u7ed3\u70b9\u7684\u6807\u6ce8\uff0c\u4ee5\u4fbf\u4ee3\u7801\u6ca1\u6709 \u81ea\u3002\u60a8\u8fd8\u53ef\u4ee5\u8df3\u8fc7\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\uff0c\u5426\u5219\uff0c\u5916\u90e8\u6807\u6ce8\u5c06\u9700\u8981\u8fd9\u4e9b\u8bbe\u7f6e sites\uff0c\u7528\u4e8e\u547d\u540d\u51ed\u636e\u4e2d\u5b9a\u4e49\u7684\u7ad9\u70b9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u547d\u540d\u51ed\u636e\u8fd8\u5305\u62ec\u53ef\u7528\u4e8e\u8def\u7531\u7684 OutboundNetworkConnection \u5b57\u6bb5 \u901a\u8fc7\u4e13\u7528\u8fde\u63a5\u8fdb\u884c\u6807\u6ce8\u3002\u901a\u8fc7\u5c06\u7aef\u70b9 URL \u548c\u8eab\u4efd\u9a8c\u8bc1\u4e0e \u6807\u6ce8\u5b9a\u4e49\u3001\u547d\u540d\u51ed\u636e\u4f7f\u6807\u6ce8\u66f4\u6613\u4e8e\u7ef4\u62a4\u3002\u4f8b\u5982\uff0c\u5982\u679c \u7ec8\u7ed3\u70b9 URL \u66f4\u6539\u65f6\uff0c\u4ec5\u66f4\u65b0\u547d\u540d\u51ed\u636e\u3002\u5f15\u7528\u547d\u540d\u7684\u6240\u6709\u6807\u6ce8 \u51ed\u636e\u53ea\u662f\u7ee7\u7eed\u5de5\u4f5c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u60a8\u6709\u591a\u4e2a\u7ec4\u7ec7\uff0c\u5219\u53ef\u4ee5\u521b\u5efa\u5177\u6709\u76f8\u540c\u540d\u79f0\u4f46\u5177\u6709 \u6bcf\u4e2a\u7ec4\u7ec7\u4e2d\u4e0d\u540c\u7684\u7aef\u70b9 URL\u3002\u7136\u540e\uff0c\u60a8\u53ef\u4ee5\u5728\u6240\u6709 orgs &#8211; \u4e00\u4e2a\u6807\u6ce8\u5b9a\u4e49\uff0c\u5f15\u7528\u8fd9\u4e9b\u547d\u540d\u51ed\u636e\u7684\u5171\u4eab\u540d\u79f0\u3002 \u4f8b\u5982\uff0c\u6bcf\u4e2a\u7ec4\u7ec7\u4e2d\u7684\u547d\u540d\u51ed\u636e\u53ef\u4ee5\u5177\u6709\u4e0d\u540c\u7684\u7ec8\u7ed3\u70b9 URL \u6765\u5bb9\u7eb3 \u5f00\u53d1\u548c\u751f\u4ea7\u73af\u5883\u7684\u5dee\u5f02\u3002\u5982\u679c Apex \u6807\u6ce8\u6307\u5b9a\u4e86\u5171\u4eab\u7684 \u8fd9\u4e9b\u547d\u540d\u51ed\u636e\u7684\u540d\u79f0\uff0c\u5b9a\u4e49\u6807\u6ce8\u7684 Apex \u7c7b\u53ef\u4ee5\u6253\u5305\uff0c\u5e76\u4e14 \u90e8\u7f72\u5728\u6240\u6709\u8fd9\u4e9b\u7ec4\u7ec7\u4e0a\uff0c\u800c\u65e0\u9700\u4ee5\u7f16\u7a0b\u65b9\u5f0f\u68c0\u67e5\u73af\u5883\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u4ece\u6807\u6ce8\u5b9a\u4e49\u4e2d\u5f15\u7528\u547d\u540d\u51ed\u636e\uff0c\u8bf7\u4f7f\u7528\u547d\u540d\u51ed\u636e URL\u3002\u4e00\u4e2a \u547d\u540d\u51ed\u8bc1 URL \u5305\u542b\u65b9\u6848\u3001\u540d\u79f0 \u7684\u547d\u540d\u51ed\u636e\u548c\u53ef\u9009\u8def\u5f84\u3002\u4f8b\u5982\uff1a\u3002<samp>callout:<\/samp><samp>callout:<\/samp><var>My_Named_Credential<\/var><samp>\/<\/samp><var>some_path<\/var><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u5c06\u67e5\u8be2\u5b57\u7b26\u4e32\u8ffd\u52a0\u5230\u547d\u540d\u51ed\u636e URL\u3002\u4f7f\u7528\u95ee\u53f7 \uff08\uff1f\uff09 \u4f5c\u4e3a\u547d\u540d\u51ed\u636e URL \u4e4b\u95f4\u7684\u5206\u9694\u7b26 \u548c\u67e5\u8be2\u5b57\u7b26\u4e32\u3002\u4f8b\u5982\uff1a\u3002<samp>callout:<\/samp><var>My_Named_Credential<\/var><samp>\/<\/samp><var>some_path<\/var><samp>?format=json<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f8b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4ee5\u4e0b Apex \u4ee3\u7801\u4e2d\uff0c\u547d\u540d\u51ed\u636e\u548c\u9644\u52a0\u8def\u5f84\u6307\u5b9a\u6807\u6ce8\u7684 \u7aef\u70b9\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HttpRequest req = new HttpRequest();\nreq.setEndpoint('callout:<em>My_Named_Credential<\/em>\/<em>some_path<\/em>');\nreq.setMethod('GET');\nHttp http = new Http();\nHTTPResponse res = http.send(req);\nSystem.debug(res.getBody());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f15\u7528\u7684\u547d\u540d\u51ed\u636e\u6307\u5b9a\u7ec8\u7ed3\u70b9 URL \u548c\u5916\u90e8\u51ed\u636e \u6307\u5b9a\u8eab\u4efd\u9a8c\u8bc1\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/developer.salesforce.com\/docs\/resources\/img\/en-us\/246.0?doc_id=dev_guides%2Fapex%2Fimages%2Fnamed_creds_as_callout_endpoints_03.png&amp;folder=apexcode\" alt=\"\u547d\u540d\u51ed\u636e\u8be6\u7ec6\u4fe1\u606f\u9875\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u65e0\u8bba\u60a8\u4f7f\u7528\u54ea\u79cd\u8eab\u4efd\u9a8c\u8bc1\uff0cApex \u4ee3\u7801\u90fd\u4fdd\u6301\u4e0d\u53d8\u3002\u8fd9 \u5916\u90e8\u51ed\u636e\u4e2d\u7684\u8eab\u4efd\u9a8c\u8bc1\u8bbe\u7f6e\u4e0d\u540c\uff0c\u5916\u90e8\u51ed\u636e\u5f15\u7528\u8eab\u4efd\u9a8c\u8bc1 \u7ec4\u7ec7\u4e2d\u5b9a\u4e49\u7684\u63d0\u4f9b\u7a0b\u5e8f\u3002<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/developer.salesforce.com\/docs\/resources\/img\/en-us\/246.0?doc_id=dev_guides%2Fapex%2Fimages%2Fnamed_creds_as_callout_endpoints_auth_02.png&amp;folder=apexcode\" alt=\"\u5177\u6709 OAuth \u9009\u9879\u7684\u547d\u540d\u51ed\u636e\u8eab\u4efd\u9a8c\u8bc1\u8bbe\u7f6e\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 \u76f8\u6bd4\u4e4b\u4e0b\uff0c\u8ba9\u6211\u4eec\u770b\u770b\u6ca1\u6709\u547d\u540d\u51ed\u636e\u7684 Apex \u4ee3\u7801\u662f\u4ec0\u4e48\u6837\u5b50\u7684\u3002\u8bf7\u6ce8\u610f\uff0c \u4ee3\u7801\u5904\u7406\u8eab\u4efd\u9a8c\u8bc1\u53d8\u5f97\u66f4\u52a0\u590d\u6742\uff0c\u5373\u4f7f\u6211\u4eec\u575a\u6301\u4f7f\u7528\u57fa\u672c\u5bc6\u7801 \u8ba4\u8bc1\u3002\u7f16\u7801 OAuth \u751a\u81f3\u66f4\u52a0\u590d\u6742\uff0c\u662f\u547d\u540d \u51ed\u636e\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HttpRequest req = new HttpRequest();\nreq.setEndpoint('<em>https:\/\/my_endpoint.example.com\/some_path<\/em>');\nreq.setMethod('GET');\n\n\/\/ Because we didn't set the endpoint as a named credential, \n\/\/ our code has to specify:\n\/\/ - The required username and password to access the endpoint\n\/\/ - The header and header information\n \nString username = '<em>myname<\/em>';\nString password = '<em>mypwd<\/em>';\n  \nBlob headerValue = Blob.valueOf(username + ':' + password);\nString authorizationHeader = 'BASIC ' +\nEncodingUtil.base64Encode(headerValue);\nreq.setHeader('Authorization', authorizationHeader);\n   \n\/\/ Create a new http object to send the request object\n\/\/ A response object is generated as a result of the request  \n  \nHttp http = new Http();\nHTTPResponse res = http.send(req);\nSystem.debug(res.getBody());<\/code><\/pre>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4f7f\u7528\u547d\u540d\u51ed\u636e<br>\u7684 Apex \u6807\u6ce8\u7684\u81ea\u5b9a\u4e49\u6807\u5934\u548c\u6b63\u6587 Salesforce \u4e3a\u547d\u540d\u51ed\u636e\u5b9a\u4e49\u7684\u7aef\u70b9\u7684\u6bcf\u4e2a\u6807\u6ce8\u751f\u6210\u4e00\u4e2a\u6807\u51c6\u6388\u6743\u6807\u5934\uff0c\u4f46\u60a8\u53ef\u4ee5\u7981\u7528\u6b64\u9009\u9879\u3002\u60a8\u7684 Apex \u4ee3\u7801\u8fd8\u53ef\u4ee5\u4f7f\u7528\u5408\u5e76\u5b57\u6bb5\u6765\u6784\u9020\u6bcf\u4e2a\u6807\u6ce8\u7684 HTTP \u6807\u5934\u548c\u6b63\u6587\u3002<\/li>\n\n\n\n<li>\u4f7f\u7528\u547d\u540d\u51ed\u8bc1<br>\u7684 Apex \u6807\u6ce8\u7684\u5408\u5e76\u5b57\u6bb5 \u8981\u6784\u9020 HTTP \u6807\u5934\u5e76\u5411\u6307\u5b9a\u4e3a\u547d\u540d\u51ed\u8bc1\u7684\u7aef\u70b9\u53d1\u51fa\u6807\u6ce8\u6b63\u6587\uff0c\u8bf7\u5728 Apex \u4ee3\u7801\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u5408\u5e76\u5b57\u6bb5\u3002<\/li>\n<\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u4f7f\u7528 named \u7684 apex \u6807\u6ce8\u7684\u81ea\u5b9a\u4e49\u6807\u5934\u548c\u6b63\u6587 \u51ed\u636e<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce \u4e3a\u6bcf\u4e2a\u6807\u6ce8\u751f\u6210\u4e00\u4e2a\u6807\u51c6\u6388\u6743\u6807\u5934\uff0c\u4ee5 named-credential-defined \u7aef\u70b9\uff0c\u4f46\u60a8\u53ef\u4ee5\u7981\u7528\u6b64\u9009\u9879\u3002\u60a8\u7684 Apex \u4ee3\u7801\u4e5f\u53ef\u4ee5\u4f7f\u7528 merge \u5b57\u6bb5\u6765\u6784\u9020\u6bcf\u4e2a\u6807\u6ce8\u7684 HTTP \u6807\u5934\u548c\u6b63\u6587\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u79cd\u7075\u6d3b\u6027\u4f7f\u60a8\u80fd\u591f\u5728\u7279\u6b8a\u60c5\u51b5\u4e0b\u4f7f\u7528\u547d\u540d\u51ed\u636e\u3002\u4f8b\u5982\uff0c\u4e00\u4e9b \u8fdc\u7a0b\u7ec8\u7ed3\u70b9\u9700\u8981\u5728\u8bf7\u6c42\u6807\u5934\u4e2d\u4f7f\u7528\u5b89\u5168\u4ee4\u724c\u6216\u52a0\u5bc6\u51ed\u636e\u3002\u4e00\u4e9b\u504f\u8fdc\u7684 \u7ec8\u7ed3\u70b9\u9700\u8981 XML \u6216 JSON \u6d88\u606f\u6b63\u6587\u4e2d\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\u81ea\u5b9a\u4e49\u6807\u6ce8 \u6807\u9898\u548c\u6b63\u6587\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce \u7ba1\u7406\u5458\u5fc5\u987b\u8bbe\u7f6e\u547d\u540d\u51ed\u636e\uff0c\u4ee5\u5141\u8bb8 Apex \u4ee3\u7801\u6784\u9020\u6807\u5934 \u6216\u5728 HTTP \u6807\u5934\u6216\u6b63\u6587\u4e2d\u4f7f\u7528\u5408\u5e76\u5b57\u6bb5\u3002\u4e0b\u8868\u63cf\u8ff0\u4e86\u8fd9\u4e9b\u6807\u6ce8 \u547d\u540d\u51ed\u636e\u7684\u9009\u9879\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u7530<\/th><th>\u63cf\u8ff0<\/th><\/tr><\/thead><tbody><tr><td><a><\/a>\u751f\u6210\u6388\u6743 \u9875\u7709<\/td><td>\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0cSalesforce \u4f1a\u751f\u6210\u4e00\u4e2a\u6388\u6743\u6807\u5934\uff0c\u5e76\u5c06\u5176\u5e94\u7528\u4e8e\u6bcf\u4e2a\u6807\u6ce8 \u5f15\u7528\u547d\u540d\u51ed\u636e\u3002\u4ec5\u5f53\u51fa\u73b0\u4ee5\u4e0b\u60c5\u51b5\u4e4b\u4e00\u65f6\u624d\u53d6\u6d88\u9009\u62e9\u6b64\u9009\u9879 \u58f0\u660e\u9002\u7528\u3002\u8fdc\u7a0b\u7ec8\u7ed3\u70b9\u4e0d\u652f\u6301\u6388\u6743\u6807\u5934\u3002\u6388\u6743\u6807\u5934\u901a\u8fc7\u5176\u4ed6\u65b9\u5f0f\u63d0\u4f9b\u3002\u4f8b\u5982\uff0c\u5728 Apex \u6807\u6ce8\u4e2d\uff0c \u5f00\u53d1\u4eba\u5458\u53ef\u4ee5\u8ba9\u4ee3\u7801\u4e3a\u6bcf\u4e2a \u6807\u6ce8\u3002\u5982\u679c\u4ece\u5916\u90e8\u5f15\u7528\u547d\u540d\u51ed\u636e\uff0c\u5219\u6b64\u9009\u9879\u662f\u5fc5\u9700\u7684 \u6570\u636e\u6e90\u3002<\/td><\/tr><tr><td><a><\/a>\u5141\u8bb8\u5728 HTTP \u4e2d\u5408\u5e76\u5b57\u6bb5 \u9875\u7709<a><\/a>\u5141\u8bb8\u5408\u5e76 HTTP \u6b63\u6587\u4e2d\u7684\u5b57\u6bb5<\/td><td>\u5728\u6bcf\u4e2a Apex \u6807\u6ce8\u4e2d\uff0c\u4ee3\u7801\u6307\u5b9a HTTP \u6807\u5934\u548c\u8bf7\u6c42\u6b63\u6587\u7684 \u6784\u5efa\u3002\u4f8b\u5982\uff0cApex \u4ee3\u7801\u53ef\u4ee5\u5728\u6388\u6743\u4e2d\u8bbe\u7f6e cookie \u7684\u503c \u9875\u7709\u3002\u8fd9\u4e9b\u9009\u9879\u4f7f Apex \u4ee3\u7801\u80fd\u591f\u4f7f\u7528\u5408\u5e76\u5b57\u6bb5\u6765\u586b\u5145 HTTP \u6807\u5934 \u5e76\u5728\u8fdb\u884c\u6807\u6ce8\u65f6\u8bf7\u6c42\u5e26\u6709\u7ec4\u7ec7\u6570\u636e\u7684\u6b63\u6587\u3002\u8fd9\u4e9b\u9009\u9879\u4e0d\u662f \u5982\u679c\u4ece\u5916\u90e8\u6570\u636e\u6e90\u5f15\u7528\u547d\u540d\u51ed\u636e\uff0c\u5219\u53ef\u7528\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">\u5408\u5e76\u4f7f\u7528\u547d\u540d\u51ed\u8bc1\u7684 Apex \u6807\u6ce8\u7684\u5b57\u6bb5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6784\u9020 HTTP \u6807\u5934\u548c\u6307\u5411\u7aef\u70b9\u7684\u6807\u6ce8\u6b63\u6587 \u6307\u5b9a\u4e3a\u547d\u540d\u51ed\u636e\uff0c\u8bf7\u5728 Apex \u4ee3\u7801\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u5408\u5e76\u5b57\u6bb5\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u5408\u5e76\u5b57\u6bb5<\/th><th>\u63cf\u8ff0<\/th><\/tr><\/thead><tbody><tr><td><samp>{!$Credential.Username}<\/samp><samp>{!$Credential.Password}<\/samp><\/td><td>\u6b63\u5728\u8fd0\u884c\u7684\u7528\u6237\u7684\u7528\u6237\u540d\u548c\u5bc6\u7801\u3002\u4ec5\u5f53\u547d\u540d\u51ed\u636e\u4f7f\u7528 \u5bc6\u7801 \u8ba4\u8bc1\u3002<code>\/\/ non-standard authentication req.setHeader('X-Username', '{!$Credential.Username}'); req.setHeader('X-Password', '{!$Credential.Password}');<\/code><\/td><\/tr><tr><td><samp>{!$Credential.OAuthToken}<\/samp><\/td><td>\u6b63\u5728\u8fd0\u884c\u7684\u7528\u6237\u7684 OAuth \u4ee4\u724c\u3002<a><\/a>\u4ec5\u5f53\u547d\u540d\u51ed\u636e\u4f7f\u7528 OAuth \u65f6\u624d\u53ef\u7528 \u8ba4\u8bc1\u3002<code>req.setHeader('Authorization', '{!$Credential.OAuthToken}');<\/code><\/td><\/tr><tr><td><samp>{!$Credential.AuthorizationMethod}<\/samp><\/td><td><a><\/a>\u6709\u6548\u503c\u53d6\u51b3\u4e8e \u547d\u540d\u51ed\u636e\u7684\u8eab\u4efd\u9a8c\u8bc1\u534f\u8bae\u3002<samp>Basic<\/samp>\u2014\u5bc6\u7801\u9a8c\u8bc1<samp>Bearer<\/samp>&#8211; OAuth 2.0<samp>null<\/samp>&#8211; \u65e0\u8eab\u4efd\u9a8c\u8bc1<\/td><\/tr><tr><td><samp>{!$Credential.AuthorizationHeaderValue}<\/samp><\/td><td>\u6709\u6548\u503c\u53d6\u51b3\u4e8e\u547d\u540d\u51ed\u636e\u7684\u8eab\u4efd\u9a8c\u8bc1\u534f\u8bae\u3002<samp><var>Base-64 encoded username and password<\/var><\/samp>\u2014\u5bc6\u7801\u9a8c\u8bc1<samp><var>OAuth token<\/var><\/samp>&#8211; OAuth 2.0<samp>null<\/samp>&#8211; \u65e0\u8eab\u4efd\u9a8c\u8bc1<\/td><\/tr><tr><td><samp>{!$Credential.OAuthConsumerKey}<\/samp><\/td><td>\u4f7f\u7528\u8005\u5bc6\u94a5\u3002\u4ec5\u5f53\u547d\u540d\u51ed\u636e\u4f7f\u7528 OAuth \u8eab\u4efd\u9a8c\u8bc1\u65f6\u624d\u53ef\u7528\u3002<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u6807\u6ce8\u7684 HTTP \u8bf7\u6c42\u6b63\u6587\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u5408\u5e76\u5b57\u6bb5\u65f6\uff0c\u53ef\u4ee5\u5e94\u7528\u516c\u5f0f\u51fd\u6570\u6765\u8f6c\u4e49\u7279\u6b8a\u5b57\u7b26\u3002 \u4e0d\u652f\u6301\u5176\u4ed6\u516c\u5f0f\u51fd\u6570\uff0c\u5e76\u4e14\u4e0d\u80fd\u7528\u4e8e HTTP \u6807\u5934\u4e2d\u7684\u5408\u5e76\u5b57\u6bb5\u3002\u4ee5\u4e0b\u793a\u4f8b\u5bf9\u7279\u6b8a\u5b57\u7b26\u8fdb\u884c\u8f6c\u4e49 \u5728 \u51ed\u636e\u3002<samp>HTMLENCODE<\/samp><samp>HTMLENCODE<\/samp><code>req.setBody('Username:{!HTMLENCODE($Credential.Username)}') req.setBody('Password:{!HTMLENCODE($Credential.Password)}')<\/code><\/li>\n\n\n\n<li>\u5728 SOAP API \u8c03\u7528\u4e2d\u4f7f\u7528\u8fd9\u4e9b\u5408\u5e76\u5b57\u6bb5\u65f6\uff0cOAuth \u8bbf\u95ee\u4ee4\u724c\u4e0d\u4f1a \u5237\u65b0\u3002<\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">SOAP \u670d\u52a1\uff1a\u4ece WSDL \u6587\u6863\u5b9a\u4e49\u7c7b<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a><\/a>\u53ef\u4ee5\u4ece WSDL \u6587\u6863\u81ea\u52a8\u751f\u6210\u7c7b\uff0c\u8be5\u6587\u6863\u5177\u6709 \u5b58\u50a8\u5728\u672c\u5730\u786c\u76d8\u9a71\u52a8\u5668\u6216\u7f51\u7edc\u4e0a\u3002\u901a\u8fc7\u4f7f\u7528 WSDL \u521b\u5efa\u7c7b \u6587\u6863\u5141\u8bb8\u5f00\u53d1\u4eba\u5458\u5728\u5176 Apex \u4ee3\u7801\u4e2d\u5bf9\u5916\u90e8 Web \u670d\u52a1\u8fdb\u884c\u6807\u6ce8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u53ef\u80fd\uff0c\u8bf7\u4f7f\u7528\u51fa\u7ad9\u6d88\u606f\u4f20\u9012\u6765\u5904\u7406\u96c6\u6210\u89e3\u51b3\u65b9\u6848\u3002\u4f7f\u7528\u6807\u6ce8\u53ef\u4ee5 \u4ec5\u5728\u5fc5\u8981\u65f6\u624d\u4f7f\u7528\u7b2c\u4e09\u65b9 Web \u670d\u52a1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4ece WSDL \u751f\u6210 Apex \u7c7b\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u5728\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u4ece\u201c\u8bbe\u7f6e\u201d\u4e2d\u8f93\u5165\u201c\u5feb\u901f\u67e5\u627e\u201d\u6846\uff0c\u7136\u540e\u9009\u62e9<strong>\u201cApex \u7c7b<\/strong>\u201d\u3002<kbd>Apex Classes<\/kbd><\/li>\n\n\n\n<li>\u5355\u51fb<strong>\u201c\u4ece WSDL \u751f\u6210<\/strong>\u201d\u3002<\/li>\n\n\n\n<li>\u5355\u51fb\u00a0<strong>Browse<\/strong>\u00a0\u5bfc\u822a\u5230\u672c\u5730\u786c\u76d8\u4e0a\u7684 WSDL \u6587\u6863 \u9a71\u52a8\u5668\u6216\u7f51\u7edc\uff0c\u6216\u952e\u5165\u5b8c\u6574\u8def\u5f84\u3002\u6b64 WSDL \u6587\u6863\u662f Apex \u7684\u57fa\u7840 \u60a8\u6b63\u5728\u521b\u5efa\u7684\u7c7b\u3002\u6ce8\u610f\u60a8\u6307\u5b9a\u7684 WSDL \u6587\u6863\u53ef\u80fd\u5305\u542b\u4e00\u4e2a SOAP \u7aef\u70b9\u4f4d\u7f6e\uff0c\u8be5\u4f4d\u7f6e \u5f15\u7528\u51fa\u7ad9\u7aef\u53e3\u3002<a><\/a>\u51fa\u4e8e\u5b89\u5168\u539f\u56e0\uff0cSalesforce \u9650\u5236\u4e86\u51fa\u7ad9\u7aef\u53e3 \u60a8\u53ef\u4ee5\u6307\u5b9a\u4ee5\u4e0b\u9009\u9879\u4e4b\u4e00\uff1a\n<ul class=\"wp-block-list\">\n<li>80\uff1a\u6b64\u7aef\u53e3\u4ec5\u63a5\u53d7 HTTP \u8fde\u63a5\u3002<\/li>\n\n\n\n<li>443\uff1a\u6b64\u7aef\u53e3\u4ec5\u63a5\u53d7 HTTPS \u8fde\u63a5\u3002<\/li>\n\n\n\n<li>1024\u201366535\uff08\u542b\uff09\uff1a\u8fd9\u4e9b\u7aef\u53e3\u63a5\u53d7 HTTP \u6216 HTTPS \u8fde\u63a5\u3002<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>\u5355\u51fb\u89e3\u6790 WSDL \u4ee5\u9a8c\u8bc1&nbsp;<strong>WSDL<\/strong>&nbsp;\u6587\u6863\u5185\u5bb9\u3002\u8fd9 \u5e94\u7528\u7a0b\u5e8f\u4e3a WSDL \u6587\u6863\u4e2d\u7684\u6bcf\u4e2a\u540d\u79f0\u7a7a\u95f4\u751f\u6210\u4e00\u4e2a\u7f3a\u7701\u7c7b\u540d\uff0c\u5e76\u4e14 \u62a5\u544a\u4efb\u4f55\u9519\u8bef\u3002\u5982\u679c WSDL \u5305\u542b\u4ee5\u4e0b\u6a21\u5f0f\u7c7b\u578b\u6216\u6784\u9020\uff0c\u5219\u89e3\u6790\u5c06\u5931\u8d25 \u4e0d\u53d7 Apex \u7c7b\u652f\u6301\uff0c\u6216\u8005\u5982\u679c\u751f\u6210\u7684\u7c7b\u8d85\u8fc7 100 \u4e07\u4e2a\u5b57\u7b26 \u5bf9 Apex \u7c7b\u7684\u9650\u5236\u3002\u4f8b\u5982\uff0c\u65e0\u6cd5\u89e3\u6790 Salesforce SOAP API WSDL\u3002<\/li>\n\n\n\n<li>\u6839\u636e\u9700\u8981\u4fee\u6539\u7c7b\u540d\u3002<a><\/a>\u867d\u7136\u60a8\u53ef\u4ee5\u4fdd\u5b58\u591a\u4e2a \u901a\u8fc7\u5bf9\u6bcf\u4e2a\u547d\u540d\u7a7a\u95f4 Apex \u4f7f\u7528\u76f8\u540c\u7684\u7c7b\u540d\uff0c\u5c06 WSDL \u547d\u540d\u7a7a\u95f4\u8f6c\u6362\u4e3a\u5355\u4e2a\u7c7b \u7c7b\u7684\u603b\u957f\u5ea6\u4e0d\u80fd\u8d85\u8fc7 100 \u4e07\u4e2a\u5b57\u7b26\u3002<\/li>\n\n\n\n<li>\u5355\u51fb&nbsp;<strong>Generate Apex<\/strong>\u3002\u5411\u5bfc\u7684\u6700\u540e\u4e00\u9875\u663e\u793a\u54ea\u4e2a \u5df2\u6210\u529f\u751f\u6210\u7c7b\uff0c\u4ee5\u53ca\u6765\u81ea\u5176\u4ed6\u7c7b\u7684\u4efb\u4f55\u9519\u8bef\u3002\u8be5\u9875\u9762\u8fd8 \u63d0\u4f9b\u7528\u4e8e\u67e5\u770b\u6210\u529f\u751f\u6210\u7684\u4ee3\u7801\u7684\u94fe\u63a5\u3002<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u6210\u529f\u751f\u6210\u7684 Apex \u7c7b\u5305\u62ec\u7528\u4e8e\u8c03\u7528 \u7531 WSDL \u6587\u6863\u8868\u793a\u7684\u7b2c\u4e09\u65b9 Web \u670d\u52a1\u3002\u8fd9\u4e9b\u7c7b\u5141\u8bb8\u60a8\u8c03\u7528 \u6765\u81ea Apex \u7684\u5916\u90e8 Web \u670d\u52a1\u3002\u5bf9\u4e8e\u6bcf\u4e2a\u751f\u6210\u7684\u7c7b\uff0c\u5c06\u521b\u5efa\u7b2c\u4e8c\u4e2a\u7c7b\uff0c\u5e76\u4f7f\u7528 \u540c\u540d\u4e14\u524d\u7f00\u4e3a .\u7b2c\u4e00\u7c7b\u662f \u7528\u4e8e\u540c\u6b65\u6807\u6ce8\u3002\u7b2c\u4e8c\u7c7b\u7528\u4e8e\u5f02\u6b65\u6807\u6ce8\u3002\u66f4\u591a\u4fe1\u606f \u5173\u4e8e\u5f02\u6b65\u6807\u6ce8\uff0c\u8bf7\u53c2\u9605\u4f7f\u7528\u5ef6\u7eed\u521b\u5efa\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u6807\u6ce8\u3002<samp>Async<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5173\u4e8e\u751f\u6210\u7684 Apex\uff0c\u8bf7\u6ce8\u610f\u4ee5\u4e0b\u51e0\u70b9\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c WSDL \u6587\u6863\u5305\u542b Apex \u4fdd\u7559\u5b57\uff0c\u5219\u5728\u751f\u6210 Apex \u7c7b\u65f6\u4f1a\u8ffd\u52a0\u8be5\u5b57\u3002\u4f8b\u5982\uff0c\u5728 WSDL \u6587\u6863\u4e2d\u8f6c\u6362\u4e3a\u5728\u751f\u6210\u7684 Apex \u7c7b\u4e2d\u3002\u8bf7\u53c2\u9605\u4fdd\u7559\u5173\u952e\u5b57\u3002\u8be6\u60c5\u8bf7\u89c1 \u5904\u7406 WSDL \u4e2d Apex \u53d8\u91cf\u4e0d\u652f\u6301\u7684\u5143\u7d20\u540d\u79f0\u4e2d\u7684\u5b57\u7b26 \u540d\u79f0\uff0c\u8bf7\u53c2\u9605\u4f7f\u7528 WSDL \u7684\u6ce8\u610f\u4e8b\u9879\u3002<samp>_xlimitlimit_x<\/samp><\/li>\n\n\n\n<li>\u5982\u679c WSDL \u4e2d\u7684\u64cd\u4f5c\u5177\u6709\u5305\u542b\u591a\u4e2a\u5143\u7d20\u7684\u8f93\u51fa\u6d88\u606f\uff0c\u90a3\u4e48 \u751f\u6210\u7684 Apex \u5c06\u5143\u7d20\u5305\u88c5\u5728\u5185\u90e8\u7c7b\u4e2d\u3002\u8868\u793a WSDL \u64cd\u4f5c\u8fd4\u56de\u5185\u90e8\u7c7b\uff0c\u800c\u4e0d\u662f\u5355\u4e2a\u5143\u7d20\u3002<\/li>\n\n\n\n<li>\u7531\u4e8e Apex \u7c7b\u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528\u53e5\u70b9 \uff08\uff09 names\uff0c\u5219\u7528\u4e8e\u751f\u6210 Apex \u7c7b\u7684 WSDL \u540d\u79f0\u4e2d\u7684\u4efb\u4f55\u53e5\u70b9\u90fd\u5c06\u66ff\u6362\u4e3a\u4e0b\u5212\u7ebf \uff08\uff09 \u5728\u751f\u6210\u7684 Apex \u4ee3\u7801\u4e2d\u3002<samp>.<\/samp><samp>_<\/samp><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece WSDL \u751f\u6210\u7c7b\u540e\uff0c\u53ef\u4ee5\u8c03\u7528\u5916\u90e8\u670d\u52a1 \u7531 WSDL \u5f15\u7528\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4f7f\u7528\u672c\u4e3b\u9898\u5176\u4f59\u90e8\u5206\u4e2d\u7684\u793a\u4f8b\u4e4b\u524d\uff0c\u5fc5\u987b\u4ece\u751f\u6210\u7684 WSDL2Apex \u4ee3\u7801\u4e2d\u590d\u5236 Apex \u7c7b\uff0c\u5e76\u5c06\u5176\u6dfb\u52a0\u5230 \u7ec4\u7ec7\u3002<samp>docSampleClass<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>\u8c03\u7528\u5916\u90e8\u670d\u52a1<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"apex_soa_invoke\">\u5728\u4f7f\u7528\u5916\u90e8\u670d\u52a1\u7684 WSDL \u6587\u6863\u540e\u8c03\u7528\u5916\u90e8\u670d\u52a1\uff0c\u4ee5\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c \u751f\u6210\u4e00\u4e2a Apex \u7c7b\uff0c\u5728 Apex \u4ee3\u7801\u4e2d\u521b\u5efa\u5b58\u6839\u7684\u5b9e\u4f8b\uff0c\u7136\u540e\u8c03\u7528 \u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u8981\u4ece Apex \u8c03\u7528\u00a0StrikeIron IP \u5730\u5740\u67e5\u627e\u670d\u52a1\uff0c\u60a8\u53ef\u4ee5 \u7f16\u5199\u7c7b\u4f3c\u4e8e\u4ee5\u4e0b\u5185\u5bb9\u7684\u4ee3\u7801\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>  \/\/ Create the stub\n  strikeironIplookup.DNSSoap dns = new strikeironIplookup.DNSSoap();\n\n  \/\/ Set up the license header\n  dns.LicenseInfo = new strikeiron.LicenseInfo();\n  dns.LicenseInfo.RegisteredUser = new strikeiron.RegisteredUser();\n  dns.LicenseInfo.RegisteredUser.UserID = 'you@company.com';\n  dns.LicenseInfo.RegisteredUser.Password = 'your-password';\n\n  \/\/ Make the Web service call\n  strikeironIplookup.DNSInfo info = dns.DNSLookup('www.myname.com');<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>HTTP \u6807\u5934\u652f\u6301<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u53ef\u4ee5\u5728 Web \u670d\u52a1\u6807\u6ce8\u4e0a\u8bbe\u7f6e HTTP \u6807\u5934\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u6b64\u529f\u80fd \u5728\u6388\u6743\u6807\u5934\u4e2d\u8bbe\u7f6e Cookie \u7684\u503c\u3002\u8981\u8bbe\u7f6e HTTP \u6807\u5934\uff0c\u8bf7\u5c06 \u548c \u6dfb\u52a0\u5230\u5b58\u6839\u3002<samp>inputHttpHeaders_x<\/samp><samp>outputHttpHeaders_x<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a><\/a>\u5728 API \u7248\u672c 16.0 \u53ca\u66f4\u65e9\u7248\u672c\u4e2d\uff0cHTTP \u54cd\u5e94 \u6807\u6ce8\u59cb\u7ec8\u4f7f\u7528 UTF-8 \u8fdb\u884c\u89e3\u7801\uff0c\u800c\u4e0d\u8003\u8651 Content-Type \u6807\u5934\u3002\u5728 API \u4e2d \u7248\u672c 17.0 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\uff0cHTTP \u54cd\u5e94\u4f7f\u7528 Content-Type \u6807\u5934\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u793a\u4f8b\u4f7f\u7528\u751f\u6210\u7684 WSDL2Apex \u4ee3\u7801\u4e2d\u7684\u793a\u4f8b WSDL \u6587\u4ef6\uff1a<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728 Web \u670d\u52a1\u6807\u6ce8\u4e0a\u53d1\u9001 HTTP \u6807\u5934<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>docSample.DocSamplePort stub = new docSample.DocSamplePort();\nstub.inputHttpHeaders_x = new Map&lt;String, String&gt;();\n\n\/\/Setting a basic authentication header\n\nstub.inputHttpHeaders_x.put('Authorization', 'Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==');\n\n\/\/Setting a cookie header\nstub.inputHttpHeaders_x.put('Cookie', 'name=value');\n\n\/\/Setting a custom HTTP header\nstub.inputHttpHeaders_x.put('myHeader', 'myValue');\n\nString input = 'This is the input string';\nString output = stub.EchoString(input);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6307\u5b9a\u4e86 for \u7684\u503c\uff0c\u5219 \u8986\u76d6\u6807\u51c6\u6807\u5934\u96c6\u3002<samp>inputHttpHeaders_x<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4ece Web \u670d\u52a1\u6807\u6ce8\u54cd\u5e94\u8bbf\u95ee HTTP \u54cd\u5e94\u6807\u5934<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>docSample.DocSamplePort stub = new docSample.DocSamplePort();\nstub.outputHttpHeaders_x = new Map&lt;String, String&gt;();\nString input = 'This is the input string';\nString output = stub.EchoString(input);\n\n\/\/Getting cookie header\nString cookie = stub.outputHttpHeaders_x.get('Set-Cookie');\n\n\/\/Getting custom header\nString myHeader = stub.outputHttpHeaders_x.get('My-Header');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u7684\u503c\u4e3a null \u8fdd\u7ea6\u3002\u60a8\u5fc5\u987b\u5728\u4e4b\u524d\u8bbe\u7f6e \u60a8\u53ef\u4ee5\u8bbf\u95ee\u54cd\u5e94\u4e2d\u6807\u5934\u7684\u5185\u5bb9\u3002<samp>outputHttpHeaders_x<\/samp><samp>outputHttpHeaders_x<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>\u652f\u6301\u7684 WSDL \u529f\u80fd<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u4ec5\u652f\u6301\u6587\u6863\u6587\u672c\u5305\u88c5\u7684 WSDL \u6837\u5f0f\u4ee5\u53ca\u4ee5\u4e0b\u57fa\u5143\u548c \u5185\u7f6e\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u67b6\u6784\u7c7b\u578b<\/th><th>\u9876\u70b9\u7c7b\u578b<\/th><\/tr><\/thead><tbody><tr><td><samp>xsd:anyURI<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:boolean<\/samp><\/td><td>\u5e03\u5c14<\/td><\/tr><tr><td><samp>xsd:date<\/samp><\/td><td>\u65e5\u671f<\/td><\/tr><tr><td><samp>xsd:dateTime<\/samp><\/td><td>\u65e5\u671f\u65f6\u95f4<\/td><\/tr><tr><td><samp>xsd:double<\/samp><\/td><td>\u53cc<\/td><\/tr><tr><td><samp>xsd:float<\/samp><\/td><td>\u53cc<\/td><\/tr><tr><td><samp>xsd:int<\/samp><\/td><td>\u6574\u6570<\/td><\/tr><tr><td><samp>xsd:integer<\/samp><\/td><td>\u6574\u6570<\/td><\/tr><tr><td><samp>xsd:language<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:long<\/samp><\/td><td>\u957f<\/td><\/tr><tr><td><samp>xsd:Name<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:NCName<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:nonNegativeInteger<\/samp><\/td><td>\u6574\u6570<\/td><\/tr><tr><td><samp>xsd:NMTOKEN<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:NMTOKENS<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:normalizedString<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:NOTATION<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:positiveInteger<\/samp><\/td><td>\u6574\u6570<\/td><\/tr><tr><td><samp>xsd:QName<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:short<\/samp><\/td><td>\u6574\u6570<\/td><\/tr><tr><td><samp>xsd:string<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:time<\/samp><\/td><td>\u65e5\u671f\u65f6\u95f4<\/td><\/tr><tr><td><samp>xsd:token<\/samp><\/td><td>\u5b57\u7b26\u4e32<\/td><\/tr><tr><td><samp>xsd:unsignedInt<\/samp><\/td><td>\u6574\u6570<\/td><\/tr><tr><td><samp>xsd:unsignedLong<\/samp><\/td><td>\u957f<\/td><\/tr><tr><td><samp>xsd:unsignedShort<\/samp><\/td><td>\u6574\u6570<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce \u6570\u636e\u7c7b\u578b anyType \u5728\u7528\u4e8e \u751f\u6210\u4f7f\u7528 API \u7248\u672c 15.0 \u53ca\u66f4\u9ad8\u7248\u672c\u4fdd\u5b58\u7684 Apex \u4ee3\u7801\u3002\u5bf9\u4e8e\u4f7f\u7528 API \u4fdd\u5b58\u7684\u4ee3\u7801 \u7248\u672c 14.0 \u53ca\u66f4\u65e9\u7248\u672c\uff0canyType \u6620\u5c04\u5230 String\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u8fd8\u652f\u6301\u4ee5\u4e0b\u67b6\u6784\u6784\u9020\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><samp>xsd:all<\/samp>\uff0c\u5728\u4f7f\u7528 API \u7248\u672c\u4fdd\u5b58\u7684 Apex \u4ee3\u7801\u4e2d 15.0 \u53ca\u66f4\u9ad8\u7248\u672c<\/li>\n\n\n\n<li><samp>xsd:annotation<\/samp>\uff0c\u5728\u4f7f\u7528 API \u4fdd\u5b58\u7684 Apex \u4ee3\u7801\u4e2d \u7248\u672c 15.0 \u53ca\u66f4\u9ad8\u7248\u672c<\/li>\n\n\n\n<li><samp>xsd:attribute<\/samp>\uff0c\u5728\u4f7f\u7528 API \u4fdd\u5b58\u7684 Apex \u4ee3\u7801\u4e2d \u7248\u672c 15.0 \u53ca\u66f4\u9ad8\u7248\u672c<\/li>\n\n\n\n<li><samp>xsd:choice<\/samp>\uff0c\u5728\u4f7f\u7528 API \u4fdd\u5b58\u7684 Apex \u4ee3\u7801\u4e2d \u7248\u672c 15.0 \u53ca\u66f4\u9ad8\u7248\u672c<\/li>\n\n\n\n<li><samp>xsd:element<\/samp>.\u5728\u4f7f\u7528 API \u4fdd\u5b58\u7684 Apex \u4ee3\u7801\u4e2d \u7248\u672c 15.0 \u53ca\u66f4\u9ad8\u7248\u672c\uff0c\u8be5\u5c5e\u6027\u4e5f\u662f \u53d7\u4ee5\u4e0b\u9650\u5236\u652f\u6301\uff1a<samp>ref<\/samp>\n<ul class=\"wp-block-list\">\n<li>\u60a8\u4e0d\u80fd\u5728\u4e0d\u540c\u7684 \u547d\u540d\u7a7a\u95f4\u3002<samp>ref<\/samp><\/li>\n\n\n\n<li>\u5168\u5c40\u5143\u7d20\u4e0d\u80fd\u4f7f\u7528 \u3002<samp>ref<\/samp><\/li>\n\n\n\n<li>\u5982\u679c\u4e00\u4e2a\u5143\u7d20\u5305\u542b \uff0c\u5219\u5b83\u4e0d\u80fd\u4e5f contain \u6216 .<samp>ref<\/samp><samp>name<\/samp><samp>type<\/samp><\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><samp>xsd:sequence<\/samp><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ec5\u5f53\u7528\u4f5c<dfn>\u547c\u5165<\/dfn>\u65f6\u624d\u652f\u6301\u4ee5\u4e0b\u6570\u636e\u7c7b\u578b\uff0c\u5373 \u5f53\u5916\u90e8 Web \u670d\u52a1\u8c03\u7528 Apex Web \u670d\u52a1\u65b9\u6cd5\u65f6\u3002\u8fd9\u4e9b\u6570\u636e\u7c7b\u578b\u4e0d\u662f \u652f\u6301\u4f5c\u4e3a<dfn>\u6807\u6ce8<\/dfn>\uff0c\u5373\u5f53 Apex Web \u670d\u52a1\u65b9\u6cd5\u8c03\u7528 \u5916\u90e8 Web \u670d\u52a1\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6591\u70b9<\/li>\n\n\n\n<li>\u5341\u8fdb\u5236<\/li>\n\n\n\n<li>\u679a\u4e3e<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u4e0d\u652f\u6301\u4efb\u4f55\u5176\u4ed6 WSDL \u6784\u9020\u3001\u7c7b\u578b\u6216\u670d\u52a1\uff0c\u5305\u62ec\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>RPC\/\u7f16\u7801\u670d\u52a1<\/li>\n\n\n\n<li>\u5177\u6709\u591a\u4e2a \u3001 \u591a\u4e2a \u7684 WSDL \u6587\u4ef6 \u670d\u52a1\u6216\u591a\u4e2a\u7ed1\u5b9a<samp>portTypes<\/samp><\/li>\n\n\n\n<li>\u5bfc\u5165\u5916\u90e8\u6a21\u5f0f\u7684 WSDL \u6587\u4ef6\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b WSDL \u7247\u6bb5 \u5bfc\u5165\u5916\u90e8\u67b6\u6784\uff0c\u8be5\u67b6\u6784\u4e0d\u662f \u652f\u6301\uff1a<code>&lt;wsdl:types&gt; &lt;xsd:schema elementFormDefault=\"qualified\" targetNamespace=\"http:\/\/s3.amazonaws.com\/doc\/2006-03-01\/\"&gt; &lt;xsd:include schemaLocation=\"AmazonS3.xsd\"\/&gt; &lt;\/xsd:schema&gt; &lt;\/wsdl:types&gt;<\/code>\u4f46\u662f\uff0c\u652f\u6301\u5728\u540c\u4e00\u67b6\u6784\u4e2d\u5bfc\u5165\u3002\u5728\u4ee5\u4e0b\u5185\u5bb9\u4e2d \u4f8b\u5982\uff0c\u5916\u90e8 WSDL \u88ab\u7c98\u8d34\u5230\u60a8\u6240\u5728\u7684 WSDL \u4e2d \u8f6c\u6362\uff1a<code>&lt;wsdl:types&gt; &lt;xsd:schema xmlns:tns=\"http:\/\/s3.amazonaws.com\/doc\/2006-03-01\/\" xmlns:xsd=\"http:\/\/www.w3.org\/2001\/XMLSchema\" elementFormDefault=\"qualified\" targetNamespace=\"http:\/\/s3.amazonaws.com\/doc\/2006-03-01\/\"&gt; &lt;xsd:element name=\"CreateBucket\"&gt; &lt;xsd:complexType&gt; &lt;xsd:sequence&gt; [...] &lt;\/xsd:schema&gt; &lt;\/wsdl:types&gt;<\/code><\/li>\n\n\n\n<li>\u4e0a\u8868\u4e2d\u672a\u8bb0\u5f55\u7684\u4efb\u4f55\u67b6\u6784\u7c7b\u578b<\/li>\n\n\n\n<li>\u8d85\u8fc7\u5927\u5c0f\u9650\u5236\u7684 WSDL\uff0c\u5305\u62ec Salesforce WSDL<\/li>\n\n\n\n<li>\u4e0d\u4f7f\u7528\u6587\u6863\u6587\u672c\u6362\u884c\u6837\u5f0f\u7684 WSDL\u3002\u4ee5\u4e0b WSDL \u4ee3\u7801\u6bb5\u4e0d\u4f7f\u7528\u6587\u6863\u6587\u5b57\u6362\u884c\u6837\u5f0f\uff0c\u5e76\u5bfc\u81f4\u201c\u65e0\u6cd5 \u67e5\u627e complexType\u201c\u9519\u8bef\u65f6 \u6d0b\u3002<code>&lt;wsdl:types&gt; &lt;xsd:schema targetNamespace=\"http:\/\/test.org\/AccountPollInterface\/\" xmlns:xsd=\"http:\/\/www.w3.org\/2001\/XMLSchema\"&gt; &lt;xsd:element name=\"SFDCPollAccountsResponse\" type=\"tns:SFDCPollResponse\"\/&gt; &lt;xsd:simpleType name=\"SFDCPollResponse\"&gt; &lt;xsd:restriction base=\"xsd:string\" \/&gt; &lt;\/xsd:simpleType&gt; &lt;\/xsd:schema&gt; &lt;\/wsdl:types&gt;<\/code>\u6b64\u4fee\u6539\u540e\u7684\u7248\u672c\u5c06\u5143\u7d20\u5305\u88c5\u4e3a \u5305\u542b\u5143\u7d20\u5e8f\u5217\u3002\u8fd9\u9075\u5faa\u6587\u6863\u6587\u672c\u6837\u5f0f\uff0c\u5e76\u4e14\u662f \u652f\u6301\u3002<samp>simpleType<\/samp><samp>complexType<\/samp><code>&lt;wsdl:types&gt; &lt;xsd:schema targetNamespace=\"http:\/\/test.org\/AccountPollInterface\/\" xmlns:xsd=\"http:\/\/www.w3.org\/2001\/XMLSchema\"&gt; &lt;xsd:element name=\"SFDCPollAccountsResponse\" type=\"tns:SFDCPollResponse\" \/&gt; &lt;xsd:complexType name=\"SFDCPollResponse\"&gt; &lt;xsd:sequence&gt; &lt;xsd:element name=\"SFDCOutput\" type=\"xsd:string\" \/&gt; &lt;\/xsd:sequence&gt; &lt;\/xsd:complexType&gt; &lt;\/xsd:schema&gt; &lt;\/wsdl:types&gt;<\/code><\/li>\n<\/ul>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u751f\u6210\u7684 WSDL2Apex \u4ee3\u7801<br>\u60a8\u53ef\u4ee5\u4f7f\u7528 WSDL2Apex \u5de5\u5177\u4ece WSDL \u6587\u6863\u751f\u6210 Apex \u7c7b\u3002WSDL2Apex \u5de5\u5177\u662f\u5f00\u6e90\u7684\uff0c\u53ef\u5728 GitHub \u4e0a\u627e\u5230\u3002<\/li>\n\n\n\n<li>\u6d4b\u8bd5 Web \u670d\u52a1\u6807\u6ce8<br>\u751f\u6210\u7684\u4ee3\u7801\u5c06\u53e6\u5b58\u4e3a Apex \u7c7b\uff0c\u5176\u4e2d\u5305\u542b\u53ef\u7528\u4e8e\u8c03\u7528 Web \u670d\u52a1\u7684\u65b9\u6cd5\u3002\u82e5\u8981\u90e8\u7f72\u6216\u6253\u5305\u6b64 Apex \u7c7b\u548c\u5176\u4ed6\u968f\u9644\u4ee3\u7801\uff0c75% \u7684\u4ee3\u7801\u5fc5\u987b\u5177\u6709\u6d4b\u8bd5\u8986\u76d6\u7387\uff0c\u5305\u62ec\u751f\u6210\u7684\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6d4b\u8bd5\u65b9\u6cd5\u4e0d\u652f\u6301 Web \u670d\u52a1\u6807\u6ce8\uff0c\u5e76\u4e14\u6267\u884c Web \u670d\u52a1\u6807\u6ce8\u7684\u6d4b\u8bd5\u4f1a\u5931\u8d25\u3002\u4e3a\u4e86\u9632\u6b62\u6d4b\u8bd5\u5931\u8d25\u5e76\u589e\u52a0\u4ee3\u7801\u8986\u76d6\u7387\uff0cApex \u63d0\u4f9b\u4e86\u5185\u7f6e\u63a5\u53e3\u548c\u65b9\u6cd5\u3002\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u4f7f\u7528\u548c\u63a5\u6536\u865a\u5047\u54cd\u5e94\u3002<samp>WebServiceMockTest.setMockWebServiceMockTest.setMock<\/samp><\/li>\n\n\n\n<li>\u6267\u884c DML \u64cd\u4f5c\u548c\u6a21\u62df\u6807\u6ce8<\/li>\n\n\n\n<li>\u4f7f\u7528 WSDL \u7684\u6ce8\u610f\u4e8b\u9879<\/li>\n<\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">\u751f\u6210\u7684 WSDL2Apex \u4ee3\u7801<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u4f7f\u7528 WSDL2Apex \u5de5\u5177\u4ece WSDL \u6587\u6863\u751f\u6210 Apex \u7c7b\u3002\u8fd9 WSDL2Apex \u5de5\u5177\u662f\u5f00\u6e90\u7684\uff0c\u53ef\u5728 GitHub \u4e0a\u627e\u5230\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u5728\u00a0GitHub \u4e0a\u7684 WSDL2Apex \u5b58\u50a8\u5e93\u4e2d\u627e\u5230\u5e76\u53c2\u4e0e WSDL2Apex\u00a0\u6e90\u4ee3\u7801\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u7684\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u4ece WSDL \u6587\u6863\u521b\u5efa Apex \u7c7b\u3002\u9876\u70b9 \u7c7b\u662f\u5728\u5bfc\u5165 WSDL \u65f6\u81ea\u52a8\u751f\u6210\u7684\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u663e\u793a\u4e86\u4e00\u4e2a\u793a\u4f8b WSDL \u516c\u6587\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;wsdl:definitions xmlns:http=\"http:\/\/schemas.xmlsoap.org\/wsdl\/http\/\"\nxmlns:soap=\"http:\/\/schemas.xmlsoap.org\/wsdl\/soap\/\"\nxmlns:s=\"http:\/\/www.w3.org\/2001\/XMLSchema\"\nxmlns:soapenc=\"http:\/\/schemas.xmlsoap.org\/soap\/encoding\/\"\nxmlns:tns=\"http:\/\/doc.sample.com\/docSample\"\ntargetNamespace=\"http:\/\/doc.sample.com\/docSample\"\nxmlns:wsdl=\"http:\/\/schemas.xmlsoap.org\/wsdl\/\"&gt;\n\n&lt;!-- Above, the schema targetNamespace maps to the Apex class name. --&gt;\n\n\n&lt;!-- Below, the type definitions for the parameters are listed. \n     Each complexType and simpleType parameteris mapped to an Apex class inside the parent class for the WSDL.  Then, each element in the complexType is mapped to a public field inside the class. --&gt;\n\n&lt;wsdl:types&gt;\n&lt;s:schema elementFormDefault=\"qualified\"\ntargetNamespace=\"http:\/\/doc.sample.com\/docSample\"&gt;\n&lt;s:element name=\"EchoString\"&gt;\n&lt;s:complexType&gt;\n&lt;s:sequence&gt;\n&lt;s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"input\" type=\"s:string\" \/&gt;\n&lt;\/s:sequence&gt;\n&lt;\/s:complexType&gt;\n&lt;\/s:element&gt;\n&lt;s:element name=\"EchoStringResponse\"&gt;\n&lt;s:complexType&gt;\n&lt;s:sequence&gt;\n&lt;s:element minOccurs=\"0\" maxOccurs=\"1\" name=\"EchoStringResult\"\ntype=\"s:string\" \/&gt;\n&lt;\/s:sequence&gt;\n&lt;\/s:complexType&gt;\n&lt;\/s:element&gt;\n&lt;\/s:schema&gt;\n&lt;\/wsdl:types&gt;\n\n&lt;!--The stub below defines operations. --&gt;\n\n&lt;wsdl:message name=\"EchoStringSoapIn\"&gt;\n&lt;wsdl:part name=\"parameters\" element=\"tns:EchoString\" \/&gt;\n&lt;\/wsdl:message&gt;\n&lt;wsdl:message name=\"EchoStringSoapOut\"&gt;\n&lt;wsdl:part name=\"parameters\" element=\"tns:EchoStringResponse\" \/&gt;\n&lt;\/wsdl:message&gt;\n&lt;wsdl:portType name=\"DocSamplePortType\"&gt;\n&lt;wsdl:operation name=\"EchoString\"&gt;\n&lt;wsdl:input message=\"tns:EchoStringSoapIn\" \/&gt;\n&lt;wsdl:output message=\"tns:EchoStringSoapOut\" \/&gt;\n&lt;\/wsdl:operation&gt;\n&lt;\/wsdl:portType&gt;\n\n&lt;!--The code below defines how the types map to SOAP. --&gt;\n\n&lt;wsdl:binding name=\"DocSampleBinding\" type=\"tns:DocSamplePortType\"&gt;\n&lt;wsdl:operation name=\"EchoString\"&gt;\n&lt;soap:operation soapAction=\"urn:dotnet.callouttest.soap.sforce.com\/EchoString\"\nstyle=\"document\" \/&gt;\n&lt;wsdl:input&gt;\n&lt;soap:body use=\"literal\" \/&gt;\n&lt;\/wsdl:input&gt;\n&lt;wsdl:output&gt;\n&lt;soap:body use=\"literal\" \/&gt;\n&lt;\/wsdl:output&gt;\n&lt;\/wsdl:operation&gt;\n&lt;\/wsdl:binding&gt;\n\n&lt;!-- Finally, the code below defines the endpoint, which maps to the endpoint in the class --&gt;\n\n&lt;wsdl:service name=\"DocSample\"&gt;\n&lt;wsdl:port name=\"DocSamplePort\" binding=\"tns:DocSampleBinding\"&gt;\n&lt;soap:address location=\"http:\/\/YourServer\/YourService\" \/&gt;\n&lt;\/wsdl:port&gt;\n&lt;\/wsdl:service&gt;\n&lt;\/wsdl:definitions&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6b64 WSDL \u6587\u6863\u4e2d\uff0c\u81ea\u52a8\u751f\u6210\u4ee5\u4e0b Apex \u7c7b\u3002\u7c7b\u540d\u662f\u60a8\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u6307\u5b9a\u7684\u540d\u79f0 \u5bfc\u5165 WSDL.<samp>docSample<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/Generated by wsdl2apex\n\npublic class docSample {\n    public class EchoStringResponse_element {\n        public String EchoStringResult;\n        private String&#91;] EchoStringResult_type_info = new String&#91;]{\n                            'EchoStringResult',\n                            'http:\/\/doc.sample.com\/docSample',\n                             null,'0','1','false'};\n        private String&#91;] apex_schema_type_info = new String&#91;]{\n                             'http:\/\/doc.sample.com\/docSample',\n                             'true','false'};\n        private String&#91;] field_order_type_info = new String&#91;]{\n                             'EchoStringResult'};\n    }\n    public class EchoString_element {\n        public String input;\n        private String&#91;] input_type_info = new String&#91;]{\n                              'input',\n                              'http:\/\/doc.sample.com\/docSample',\n                               null,'0','1','false'};\n        private String&#91;] apex_schema_type_info = new String&#91;]{\n                               'http:\/\/doc.sample.com\/docSample',\n                               'true','false'};\n        private String&#91;] field_order_type_info = new String&#91;]{'input'};\n    }\n    public class DocSamplePort {\n        public String endpoint_x = 'http:\/\/YourServer\/YourService';\n        public Map&lt;String,String&gt; inputHttpHeaders_x;\n        public Map&lt;String,String&gt; outputHttpHeaders_x;\n        public String clientCertName_x;\n        public String clientCert_x;\n        public String clientCertPasswd_x;\n        public Integer timeout_x;\n        private String&#91;] ns_map_type_info = new String&#91;]{\n                          'http:\/\/doc.sample.com\/docSample', 'docSample'};\n        public String EchoString(String input) {\n            docSample.EchoString_element request_x = new \n                                           docSample.EchoString_element();\n            request_x.input = input;\n            docSample.EchoStringResponse_element response_x;\n            Map&lt;String, docSample.EchoStringResponse_element&gt; response_map_x = \n                       new Map&lt;String, docSample.EchoStringResponse_element&gt;();\n            response_map_x.put('response_x', response_x);\n            WebServiceCallout.invoke(\n              this,\n              request_x,\n              response_map_x,\n              new String&#91;]{endpoint_x,\n              'urn:dotnet.callouttest.soap.sforce.com\/EchoString',\n              'http:\/\/doc.sample.com\/docSample',\n              'EchoString',\n              'http:\/\/doc.sample.com\/docSample',\n              'EchoStringResponse',\n              'docSample.EchoStringResponse_element'}\n            );\n            response_x = response_map_x.get('response_x');\n            return response_x.EchoStringResult;\n        }\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8bf7\u6ce8\u610f\u539f\u59cb WSDL \u6587\u6863\u4e2d\u7684\u4ee5\u4e0b\u6620\u5c04\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>WSDL \u76ee\u6807\u547d\u540d\u7a7a\u95f4\u6620\u5c04\u5230 Apex \u7c7b\u540d\u3002<\/li>\n\n\n\n<li>\u6bcf\u4e2a\u590d\u6742\u7c7b\u578b\u90fd\u6210\u4e3a\u4e00\u4e2a\u7c7b\u3002\u7c7b\u578b\u4e2d\u7684\u6bcf\u4e2a\u5143\u7d20\u90fd\u662f \u7c7b\u3002<\/li>\n\n\n\n<li>WSDL \u7aef\u53e3\u540d\u79f0\u6620\u5c04\u5230\u5b58\u6839\u7c7b\u3002<\/li>\n\n\n\n<li>WSDL \u4e2d\u7684\u6bcf\u4e2a\u64cd\u4f5c\u90fd\u6620\u5c04\u5230\u4e00\u4e2a\u516c\u5171\u65b9\u6cd5\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u4f7f\u7528\u81ea\u52a8\u751f\u6210\u7684\u7c7b\u6765 \u8c03\u7528\u5916\u90e8 Web \u670d\u52a1\u3002\u4e0b\u9762\u7684\u4ee3\u7801\u5728\u5916\u90e8\u670d\u52a1\u5668\u4e0a\u8c03\u7528\u8be5\u65b9\u6cd5\u3002<samp>docSample<\/samp><samp>echoString<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docSample.DocSamplePort stub = new docSample.DocSamplePort();\nString input = 'This is the input string';\nString output = stub.EchoString(input);<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u6d4b\u8bd5 Web \u670d\u52a1\u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u751f\u6210\u7684\u4ee3\u7801\u5c06\u53e6\u5b58\u4e3a Apex \u7c7b\uff0c\u5176\u4e2d\u5305\u542b\u60a8\u53ef\u4ee5\u8c03\u7528\u7684\u65b9\u6cd5 \u8c03\u7528 Web \u670d\u52a1\u3002\u82e5\u8981\u90e8\u7f72\u6216\u6253\u5305\u6b64 Apex \u7c7b\u548c\u5176\u4ed6\u968f\u9644\u4ee3\u7801\uff0c 75% \u7684\u4ee3\u7801\u5fc5\u987b\u5177\u6709\u6d4b\u8bd5\u8986\u76d6\u7387\uff0c\u5305\u62ec\u751f\u6210\u7684\u7c7b\u4e2d\u7684\u65b9\u6cd5\u3002\u7531 \u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6d4b\u8bd5\u65b9\u6cd5\u4e0d\u652f\u6301 Web \u670d\u52a1\u6807\u6ce8\u548c\u6267\u884c Web \u7684\u6d4b\u8bd5 \u670d\u52a1\u6807\u6ce8\u5931\u8d25\u3002\u4e3a\u4e86\u9632\u6b62\u6d4b\u8bd5\u5931\u8d25\u5e76\u589e\u52a0\u4ee3\u7801\u8986\u76d6\u7387\uff0cApex \u63d0\u4f9b\u5185\u7f6e\u63a5\u53e3\u548c \u65b9\u6cd5\u3002\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u4f7f\u7528\u548c\u63a5\u6536\u865a\u5047\u54cd\u5e94\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><samp>WebServiceMock<\/samp><samp>Test.setMock<\/samp><samp>WebServiceMock<\/samp><samp>Test.setMock<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6307\u5b9a\u7528\u4e8e\u6d4b\u8bd5 Web \u670d\u52a1\u6807\u6ce8\u7684\u6a21\u62df\u54cd\u5e94<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece WSDL \u521b\u5efa Apex \u7c7b\u65f6\uff0c\u81ea\u52a8\u751f\u6210\u7684\u7c7b\u4e2d\u7684\u65b9\u6cd5 \u8c03\u7528 \uff0c\u5176\u4e2d \u6267\u884c\u5bf9\u5916\u90e8\u670d\u52a1\u7684\u6807\u6ce8\u3002\u6d4b\u8bd5\u8fd9\u4e9b\u65b9\u6cd5\u65f6\uff0c\u60a8\u53ef\u4ee5 \u6307\u793a Apex \u8fd0\u884c\u65f6\u5728\u8c03\u7528\u65f6\u751f\u6210\u865a\u5047\u54cd\u5e94\u3002\u4e3a\u6b64\uff0c \u5b9e\u73b0\u63a5\u53e3\u548c \u6307\u5b9a\u8981\u53d1\u9001\u7684 Apex \u8fd0\u884c\u65f6\u7684\u865a\u5047\u54cd\u5e94\u3002\u4ee5\u4e0b\u662f\u66f4\u591a\u6b65\u9aa4 \u7ec6\u8282\u3002<samp>WebServiceCallout.invoke<\/samp><samp>WebServiceCallout.invoke<\/samp><samp>WebServiceMock<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u5b9e\u73b0\u63a5\u53e3 \u5e76\u5728\u65b9\u6cd5\u4e2d\u6307\u5b9a false \u54cd\u5e94\u3002<samp>WebServiceMock<\/samp><samp>doInvoke<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>global class <em>YourWebServiceMockImpl<\/em> implements WebServiceMock {\n   global void doInvoke(\n           Object stub,\n           Object request,\n           Map&lt;String, Object&gt; response,\n           String endpoint,\n           String soapAction,\n           String requestName,\n           String responseNS,\n           String responseName,\n           String responseType) {\n\n        \/\/ Create response element from the autogenerated class.\n        \/\/ Populate response element.\n        \/\/ Add response element to the response parameter, as follows:\n        response.put('response_x', <em>responseElement<\/em>); \n   }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9e\u73b0\u63a5\u53e3\u7684\u7c7b\u53ef\u4ee5\u662f\u5168\u5c40\u7c7b\uff0c\u4e5f\u53ef\u4ee5\u662f\u516c\u5171\u7c7b\u3002<samp>WebServiceMock<\/samp><\/li>\n\n\n\n<li>\u60a8\u53ef\u4ee5\u4f7f\u7528<samp>@isTest<\/samp>\u5bf9\u6b64\u7c7b\u8fdb\u884c\u6279\u6ce8\uff0c\u56e0\u4e3a\u5b83\u4ec5\u5728\u6d4b\u8bd5\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u3002 \u8fd9\u6837\uff0c\u60a8\u5c31\u53ef\u4ee5\u5c06\u5176\u4ece\u7ec4\u7ec7\u7684\u4ee3\u7801\u5927\u5c0f\u9650\u5236 6 \u4e2d\u6392\u9664 MB\u7684\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\uff0c\u60a8\u5df2\u7ecf\u6307\u5b9a\u4e86\u5047\u54cd\u5e94\u7684\u503c\uff0c\u8bf7\u6307\u793a Apex \u8fd0\u884c\u65f6\u901a\u8fc7\u8c03\u7528\u6d4b\u8bd5\u65b9\u6cd5\u53d1\u9001\u6b64\u865a\u5047\u54cd\u5e94\u3002\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u4f20\u9012 \uff0c\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u53c2\u6570 \u53c2\u6570\uff0c\u5219\u4f20\u9012 \u7684\u63a5\u53e3\u5b9e\u73b0\u7684\u65b0\u5b9e\u4f8b\uff0c\u5982\u4e0b\u6240\u793a\uff1a<samp>Test.setMock<\/samp><samp>WebServiceMock.class<\/samp><samp>WebServiceMock<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Test.setMock(WebServiceMock.class, new <em>YourWebServiceMockImpl<\/em>());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6b64\u4e4b\u540e\uff0c\u5982\u679c\u5728\u6d4b\u8bd5\u4e0a\u4e0b\u6587\u4e2d\u8c03\u7528 Web \u670d\u52a1\u6807\u6ce8\uff0c\u5219\u6807\u6ce8\u4e3a \u4e0d\u662f\u5236\u9020\u7684\u3002\u60a8\u4f1a\u6536\u5230\u65b9\u6cd5\u5b9e\u73b0\u4e2d\u6307\u5b9a\u7684\u6a21\u62df\u54cd\u5e94\u3002<samp>doInvoke<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6267\u884c\u6807\u6ce8\u7684\u4ee3\u7801\u4f4d\u4e8e \u4e00\u4e2a\u6258\u7ba1\u5305\uff0c\u4ece \u6d4b\u8bd5\u65b9\u6cd5\u3002<samp>Test.setMock<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u6d4b\u8bd5 Web \u670d\u52a1\u6807\u6ce8\u3002\u5217\u51fa\u4e86\u63a5\u53e3\u7684\u5b9e\u73b0 \u7b2c\u4e00\u3002\u6b64\u793a\u4f8b\u5b9e\u73b0\u8be5\u65b9\u6cd5\uff0c\u8be5\u65b9\u6cd5\u8fd4\u56de\u60a8\u6307\u5b9a\u7684\u54cd\u5e94\u3002\u5728\u672c\u4f8b\u4e2d\uff0c\u54cd\u5e94\u5143\u7d20 \u7684\u81ea\u52a8\u751f\u6210\u7684\u7c7b\u88ab\u521b\u5efa\u5e76\u5206\u914d\u4e00\u4e2a\u503c\u3002\u63a5\u4e0b\u6765\uff0c\u54cd\u5e94\u6620\u5c04 \u53c2\u6570\u586b\u5145\u4e86\u6b64\u865a\u5047\u54cd\u5e94\u3002\u6b64\u793a\u4f8b\u57fa\u4e8e WSDL \u5728\u751f\u6210\u7684 WSDL2Apex \u4ee3\u7801\u4e2d\u5217\u51fa\u3002\u5bfc\u5165\u6b64 WSDL \u5e76\u751f\u6210 \u4fdd\u5b58\u4e4b\u524d\u8c03\u7528\u7684\u7c7b \u8fd9\u4e2a\u73ed\u7ea7\u3002<samp>WebServiceMockdoInvokedocSample<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nglobal class WebServiceMockImpl implements WebServiceMock {\n   global void doInvoke(\n           Object stub,\n           Object request,\n           Map&lt;String, Object&gt; response,\n           String endpoint,\n           String soapAction,\n           String requestName,\n           String responseNS,\n           String responseName,\n           String responseType) {\n       docSample.EchoStringResponse_element respElement = \n           new docSample.EchoStringResponse_element();\n       respElement.EchoStringResult = 'Mock response';\n       response.put('response_x', respElement); \n   }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u65b9\u6cd5\u751f\u6210 Web \u670d\u52a1\u6807\u6ce8\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class WebSvcCallout {\n    public static String callEchoString(String input) {\n        docSample.DocSamplePort sample = new docSample.DocSamplePort();\n        sample.endpoint_x = 'https:\/\/example.com\/example\/test';\n        \n        \/\/ This invokes the EchoString method in the generated class\n        String echo = sample.EchoString(input);\n        \n        return echo;\n    }   \n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u6d4b\u8bd5\u7c7b\u5305\u542b\u8bbe\u7f6e\u6a21\u62df\u6807\u6ce8\u6a21\u5f0f\u7684\u6d4b\u8bd5\u65b9\u6cd5\u3002\u5b83\u8c03\u7528 \u4e0a\u4e00\u4e2a\u65b9\u6cd5 \u7c7b\uff0c\u5e76\u9a8c\u8bc1\u662f\u5426\u6536\u5230\u6a21\u62df\u54cd\u5e94\u3002<samp>callEchoString<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nprivate class WebSvcCalloutTest {\n    @isTest static void testEchoString() {              \n        \/\/ This causes a fake response to be generated\n        Test.setMock(WebServiceMock.class, new WebServiceMockImpl());\n        \n        \/\/ Call the method that invokes a callout\n        String output = WebSvcCallout.callEchoString('Hello World!');\n        \n        \/\/ Verify that a fake result is returned\n        System.assertEquals('Mock response', output); \n    }\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u6267\u884c DML \u64cd\u4f5c\u548c\u6a21\u62df\u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6807\u6ce8\u4e0d\u662f \u5141\u8bb8\u5728\u540c\u4e00\u4e8b\u52a1\u4e2d\u6267\u884c DML \u64cd\u4f5c\u540e\uff0c\u56e0\u4e3a DML \u64cd\u4f5c \u5bfc\u81f4\u5f85\u5904\u7406\u7684\u672a\u63d0\u4ea4\u5de5\u4f5c\uff0c\u4ece\u800c\u963b\u6b62\u6807\u6ce8\u6267\u884c\u3002 \u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u63d2\u5165\u6d4b\u8bd5\u6570\u636e \u5728\u8fdb\u884c\u6807\u6ce8\u4e4b\u524d\u4f7f\u7528 DML\u3002\u8981\u542f\u7528\u6b64\u529f\u80fd\uff0c\u8bf7\u5c06\u90e8\u5206\u62ec\u8d77\u6765 \u5728 AND \u8bed\u53e5\u4e2d\u6267\u884c\u6807\u6ce8\u7684\u4ee3\u7801\u3002\u8bed\u53e5\u5fc5\u987b\u51fa\u73b0 \u5728\u58f0\u660e\u4e4b\u524d\u3002 \u6b64\u5916\uff0c\u5bf9 DML \u64cd\u4f5c\u7684\u8c03\u7528\u4e0d\u5f97\u662f \/ \u5757\u7684\u4e00\u90e8\u5206\u3002<samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><samp>Test.startTest<\/samp><samp>Test.setMock<\/samp><samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DML \u64cd\u4f5c \u5728\u6a21\u62df\u6807\u6ce8\u88ab\u5141\u8bb8\u4e14\u4e0d\u9700\u8981\u4e4b\u540e\u53d1\u751f \u6d4b\u8bd5\u65b9\u6cd5\u7684\u4efb\u4f55\u53d8\u5316\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728\u6a21\u62df\u6807\u6ce8\u4e4b\u524d\u6267\u884c DML<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u57fa\u4e8e\u524d\u9762\u7684\u793a\u4f8b\u3002\u8be5\u793a\u4f8b\u663e\u793a \u5982\u4f55\u4f7f\u7528 AND \u8bed\u53e5\u5141\u8bb8 \u5728\u6a21\u62df\u6807\u6ce8\u4e4b\u524d\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u6267\u884c\u7684 DML \u64cd\u4f5c\u3002 \u6d4b\u8bd5\u65b9\u6cd5\uff08\uff09\u9996\u5148\u63d2\u5165\u4e00\u4e2a\u6d4b\u8bd5\u5e10\u6237\uff0c\u8c03\u7528\uff0c\u4f7f\u7528\u8bbe\u7f6e\u6a21\u62df\u6807\u6ce8\u6a21\u5f0f\uff0c\u8c03\u7528\u4e00\u4e2a\u65b9\u6cd5 \u6267\u884c\u6807\u6ce8\uff0c\u9a8c\u8bc1\u6a21\u62df\u54cd\u5e94\u503c\uff0c\u6700\u540e \u8c03\u7528\u3002<samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><samp>testEchoString<\/samp><samp>Test.startTest<\/samp><samp>Test.setMock<\/samp><samp>Test.stopTest<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nprivate class WebSvcCalloutTest {\n    @isTest static void testEchoString() {              \n        \/\/ Perform some DML to insert test data\n        Account testAcct = new Account('Test Account');\n        insert testAcct;\n\n        \/\/ Call Test.startTest before performing callout\n        \/\/ but after setting test data.\n        Test.startTest();\n\n        \/\/ Set mock callout class \n        Test.setMock(WebServiceMock.class, new WebServiceMockImpl());\n        \n        \/\/ Call the method that invokes a callout\n        String output = WebSvcCallout.callEchoString('Hello World!');\n        \n        \/\/ Verify that a fake result is returned\n        System.assertEquals('Mock response', output);\n\n        Test.stopTest();\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f02\u6b65\u9876\u70b9\u548c\u6a21\u62df\u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0e DML \u7c7b\u4f3c\uff0c\u5f02\u6b65 Apex \u64cd\u4f5c\u4f1a\u5bfc\u81f4\u6302\u8d77\u7684\u672a\u63d0\u4ea4\u5de5\u4f5c\uff0c\u4ece\u800c\u963b\u6b62 \u7a0d\u540e\u5728\u540c\u4e00\u4e8b\u52a1\u4e2d\u6267\u884c\u7684\u6807\u6ce8\u3002\u793a\u4f8b \u5f02\u6b65 Apex \u64cd\u4f5c\u662f\u5bf9\u672a\u6765\u65b9\u6cd5\u3001\u6279\u5904\u7406 Apex \u6216\u8ba1\u5212\u7684\u8c03\u7528 \u9876\u70b9\u3002\u8fd9\u4e9b\u5f02\u6b65\u8c03\u7528\u901a\u5e38\u5305\u542b\u5728\u6d4b\u8bd5\u65b9\u6cd5\u7684 and \u8bed\u53e5\u4e2d\uff0c\u4ee5\u4fbf \u5b83\u4eec\u5728 \u4e4b\u540e\u6267\u884c\u3002\u5728\u8fd9\u4e2a \u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u5728\u5f02\u6b65\u8c03\u7528\u540e\u6267\u884c\u6a21\u62df\u6807\u6ce8\uff0c\u5e76\u4e14\u4e0d\u4f1a\u8fdb\u884c\u4efb\u4f55\u66f4\u6539 \u5fc5\u8981\u3002\u4f46\u662f\uff0c\u5982\u679c\u5f02\u6b65\u8c03\u7528\u6ca1\u6709\u5305\u542b\u5728 and \u8bed\u53e5\u4e2d\uff0c\u4f60\u5c06\u5f97\u5230\u4e00\u4e2a \u5f02\u5e38\uff0c\u56e0\u4e3a\u672a\u63d0\u4ea4\u7684\u5de5\u4f5c\u5904\u4e8e\u5f85\u5904\u7406\u72b6\u6001\u3002\u8981\u9632\u6b62\u6b64\u5f02\u5e38\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u4efb\u4e00\u64cd\u4f5c \u5176\u4e2d\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><samp>Test.stopTest<\/samp><samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5c06\u5f02\u6b65\u8c03\u7528\u5305\u542b\u5728 and \u8bed\u53e5\u4e2d\u3002<samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><code>Test.startTest(); MyClass.asyncCall(); Test.stopTest(); Test.setMock(..); \/\/ Takes two arguments MyClass.mockCallout();<\/code><\/li>\n\n\n\n<li>\u9075\u5faa\u4e0e DML \u8c03\u7528\u76f8\u540c\u7684\u89c4\u5219\uff1a\u5c06\u4ee3\u7801\u90e8\u5206\u62ec\u8d77\u6765 \u5728 AND \u8bed\u53e5\u4e2d\u6267\u884c\u6807\u6ce8\u3002\u8bed\u53e5\u5fc5\u987b\u51fa\u73b0\u5728\u8bed\u53e5\u4e4b\u524d\u3002\u6b64\u5916\uff0c \u5f02\u6b65\u8c03\u7528\u4e0d\u80fd\u662f \/ \u5757\u7684\u4e00\u90e8\u5206\u3002<samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><samp>Test.startTest<\/samp><samp>Test.setMock<\/samp><samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><code>MyClass.asyncCall(); Test.startTest(); Test.setMock(..); \/\/ Takes two arguments MyClass.mockCallout(); Test.stopTest();<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6a21\u62df\u6807\u6ce8\u4e4b\u540e\u53d1\u751f\u7684\u5f02\u6b65\u8c03\u7528\u662f \u5141\u8bb8\u5e76\u4e14\u4e0d\u9700\u8981\u5bf9\u6d4b\u8bd5\u65b9\u6cd5\u8fdb\u884c\u4efb\u4f55\u66f4\u6539\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528 WSDL \u7684\u6ce8\u610f\u4e8b\u9879<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece WSDL \u751f\u6210 Apex \u7c7b\u65f6\uff0c\u8bf7\u6ce8\u610f\u4ee5\u4e0b\u4e8b\u9879\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6620\u5c04\u6807\u5934<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WSDL \u6587\u6863\u4e2d\u5b9a\u4e49\u7684\u6807\u5934\u5c06\u6210\u4e3a\u751f\u6210\u7684\u7c7b\u4e2d\u5b58\u6839\u4e0a\u7684\u516c\u5171\u5b57\u6bb5\u3002 \u8fd9\u7c7b\u4f3c\u4e8e AJAX \u5de5\u5177\u5305\u548c .NET \u7684\u5de5\u4f5c\u65b9\u5f0f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e86\u89e3\u8fd0\u884c\u65f6\u4e8b\u4ef6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53 Apex \u4ee3\u7801\u5bf9\u5916\u90e8\u670d\u52a1\u8fdb\u884c\u6807\u6ce8\u65f6\uff0c\u5c06\u6267\u884c\u4ee5\u4e0b\u68c0\u67e5\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u6709\u5173\u53d1\u51fa HTTP \u8bf7\u6c42\u6216 Web \u670d\u52a1\u8c03\u7528\u65f6\u7684\u8d85\u65f6\u9650\u5236\u7684\u4fe1\u606f\uff0c\u8bf7\u53c2\u89c1\u6807\u6ce8\u9650\u5236\u548c\u5c40\u9650\u6027\u3002<\/li>\n\n\n\n<li>\u4e0d\u5141\u8bb8\u5728 Apex \u7c7b\u4e2d\u4f7f\u7528\u5faa\u73af\u5f15\u7528\u3002<\/li>\n\n\n\n<li>\u4e0d\u5141\u8bb8\u4e0e Salesforce \u57df\u5efa\u7acb\u591a\u4e2a\u73af\u56de\u8fde\u63a5\u3002<\/li>\n\n\n\n<li>\u82e5\u8981\u5141\u8bb8\u8bbf\u95ee\u7ec8\u7ed3\u70b9\uff0c\u8bf7\u4ece\u5b89\u88c5\u7a0b\u5e8f\u4e2d\u8f93\u5165\u201c\u5feb\u901f\u67e5\u627e\u201d\u6846\uff0c\u7136\u540e\u9009\u62e9<strong>\u201c\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e<\/strong>\u201d\u6765\u6ce8\u518c\u8be5\u7ec8\u7ed3\u70b9\u3002<kbd>Remote Site Settings<\/kbd><\/li>\n\n\n\n<li>\u4e3a\u4e86\u9632\u6b62\u6570\u636e\u5e93\u8fde\u63a5\u88ab\u963b\u6b62\uff0c\u6ca1\u6709\u4e8b\u52a1 \u53ef\u4ee5\u6253\u5f00\u3002<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e86\u89e3\u53d8\u91cf\u540d\u79f0\u4e2d\u4e0d\u652f\u6301\u7684\u5b57\u7b26<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">WSDL \u6587\u4ef6\u53ef\u4ee5\u5305\u542b Apex \u53d8\u91cf\u540d\u79f0\u4e2d\u4e0d\u5141\u8bb8\u7684\u5143\u7d20\u540d\u79f0\u3002\u8fd9 \u4ece WSDL \u751f\u6210 Apex \u53d8\u91cf\u540d\u79f0\u65f6\uff0c\u4ee5\u4e0b\u89c4\u5219\u9002\u7528 \u6587\u4ef6\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5982\u679c\u5143\u7d20\u540d\u79f0\u7684\u7b2c\u4e00\u4e2a\u5b57\u7b26\u4e0d\u662f\u5b57\u6bcd\u987a\u5e8f\uff0c\u5219\u4f1a\u5728\u751f\u6210\u7684 Apex \u524d\u9762\u9644\u52a0\u4e00\u4e2a\u5b57\u7b26 \u53d8\u91cf\u540d\u79f0\u3002<samp>x<\/samp><\/li>\n\n\n\n<li>\u5982\u679c Apex \u53d8\u91cf\u540d\u79f0\u4e2d\u4e0d\u5141\u8bb8\u4f7f\u7528\u5143\u7d20\u540d\u79f0\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u7b26\uff0c\u5219\u4f1a\u5728 \u751f\u6210\u7684 Apex \u53d8\u91cf\u540d\u79f0\u3002<samp>x<\/samp><\/li>\n\n\n\n<li>\u5982\u679c\u5143\u7d20\u540d\u79f0\u5305\u542b Apex \u53d8\u91cf\u540d\u79f0\u4e2d\u4e0d\u5141\u8bb8\u7684\u5b57\u7b26\uff0c\u5219 \u5b57\u7b26\u66ff\u6362\u4e3a\u4e0b\u5212\u7ebf \uff08\uff09 \u5b57\u7b26\u3002<samp>_<\/samp><\/li>\n\n\n\n<li>\u5982\u679c\u5143\u7d20\u540d\u79f0\u5728\u4e00\u884c\u4e2d\u5305\u542b\u4e24\u4e2a Apex \u53d8\u91cf\u4e2d\u4e0d\u5141\u8bb8\u7684\u5b57\u7b26 name\uff0c\u7b2c\u4e00\u4e2a\u5b57\u7b26\u66ff\u6362\u4e3a\u4e0b\u5212\u7ebf \uff08\uff09 \u5b57\u7b26\uff0c\u7b2c\u4e8c\u4e2a\u5b57\u7b26 \u66ff\u6362\u4e3a\u5b57\u7b26\u3002\u8fd9\u6837\u53ef\u4ee5\u907f\u514d\u751f\u6210\u5177\u6709\u4e24\u4e2a\u8fde\u7eed\u53d8\u91cf\u540d\u79f0\u7684\u53d8\u91cf\u540d\u79f0 \u4e0b\u5212\u7ebf\uff0c\u8fd9\u5728 Apex \u4e2d\u662f\u4e0d\u5141\u8bb8\u7684\u3002<samp>_<\/samp><samp>x<\/samp><\/li>\n\n\n\n<li>\u5047\u8bbe\u60a8\u6709\u4e00\u4e2a\u64cd\u4f5c\uff0c\u8be5\u64cd\u4f5c\u91c7\u7528\u4e24\u4e2a\u53c2\u6570\u548c . \u751f\u6210\u7684 Apex \u6709\u4e24\u4e2a\u53d8\u91cf\uff0c\u5747\u547d\u540d\u4e3a .\u8be5\u7c7b\u4e0d\u7f16\u8bd1\u3002 \u624b\u52a8\u7f16\u8f91 Apex \u5e76\u66f4\u6539\u5176\u4e2d\u4e00\u4e2a\u53d8\u91cf\u540d\u79f0\u3002<samp>a_<\/samp><samp>a_x<\/samp><samp>a_x<\/samp><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u8c03\u8bd5\u4ece WSDL \u6587\u4ef6\u751f\u6210\u7684\u7c7b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Salesforce \u4f7f\u7528 SOAP API\u3001.NET \u548c Axis \u6d4b\u8bd5\u4ee3\u7801\u3002\u5982\u679c\u60a8\u4f7f\u7528\u5176\u4ed6\u5de5\u5177\uff0c\u60a8\u53ef\u80fd\u4f1a\u9047\u5230 \u95ee\u9898\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u4f7f\u7528\u8c03\u8bd5\u6807\u5934\u5728\u8bf7\u6c42\u548c\u54cd\u5e94 SOAP \u6d88\u606f\u4e2d\u8fd4\u56de XML \u4ee5\u5e2e\u52a9 \u60a8\u8bca\u65ad\u95ee\u9898\u3002\u6709\u5173\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u4f7f\u7528 SOAP API \u90e8\u7f72 Apex\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8c03\u7528 HTTP \u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u63d0\u4f9b\u4e86\u51e0\u4e2a\u5185\u7f6e\u7c7b\u6765\u5904\u7406 HTTP \u670d\u52a1\u5e76\u521b\u5efa HTTP \u8bf7\u6c42\uff0c\u4f8b\u5982 GET\u3001POST\u3001PUT \u548c DELETE\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u4f7f\u7528\u8fd9\u4e9b HTTP \u7c7b\u96c6\u6210\u5230\u57fa\u4e8e REST \u7684\u670d\u52a1\u3002\u5b83\u4eec\u8fd8\u5141\u8bb8\u60a8 \u96c6\u6210\u5230\u57fa\u4e8e SOAP \u7684 Web \u670d\u52a1\u4e2d\uff0c\u4f5c\u4e3a\u4ece WSDL \u751f\u6210 Apex \u4ee3\u7801\u7684\u66ff\u4ee3\u9009\u9879\u3002 \u901a\u8fc7\u4f7f\u7528 HTTP \u7c7b\uff0c\u800c\u4e0d\u662f\u4ece WSDL \u5f00\u59cb\uff0c\u60a8\u53ef\u4ee5\u627f\u62c5\u66f4\u591a\u7684\u8d23\u4efb \u5904\u7406\u8bf7\u6c42\u548c\u54cd\u5e94\u7684 SOAP \u6d88\u606f\u7684\u6784\u9020\u3002<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>HTTP \u7c7b<\/li>\n\n\n\n<li>\u6d4b\u8bd5 HTTP \u6807\u6ce8<br>\u8981\u90e8\u7f72\u6216\u6253\u5305 Apex\uff0c75% \u7684\u4ee3\u7801\u5fc5\u987b\u5177\u6709\u6d4b\u8bd5\u8986\u76d6\u7387\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6d4b\u8bd5\u65b9\u6cd5\u4e0d\u652f\u6301 HTTP \u6807\u6ce8\uff0c\u56e0\u6b64\u6267\u884c\u6807\u6ce8\u7684\u6d4b\u8bd5\u4f1a\u5931\u8d25\u3002\u901a\u8fc7\u4f7f\u7528\u6307\u793a Apex \u5728\u6d4b\u8bd5\u4e2d\u751f\u6210\u6a21\u62df\u54cd\u5e94\u6765\u542f\u7528 HTTP \u6807\u6ce8\u6d4b\u8bd5\u3002<samp>Test.setMock<\/samp><\/li>\n<\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">HTTP \u7c7b<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u4e9b\u7c7b\u516c\u5f00 HTTP \u8bf7\u6c42\u548c\u54cd\u5e94\u529f\u80fd\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><samp>Http\u7684 \u7c7b<\/samp>\u3002\u4f7f\u7528\u6b64\u7c7b\u6765\u542f\u52a8 HTTP \u8bf7\u6c42\u548c \u54cd\u5e94\u3002<\/li>\n\n\n\n<li>HttpRequest \u7c7b\uff1a\u4f7f\u7528\u6b64\u7c7b\u53ef\u4ee5 \u4ee5\u7f16\u7a0b\u65b9\u5f0f\u521b\u5efa HTTP \u8bf7\u6c42\uff0c\u5982 GET\u3001POST\u3001PATCH\u3001PUT \u548c DELETE\u3002<\/li>\n\n\n\n<li>HttpResponse \u7c7b\uff1a\u4f7f\u7528\u6b64\u7c7b\u53ef\u4ee5 \u5904\u7406 \u8fd4\u56de\u7684 HTTP \u54cd\u5e94\u3002<samp>HTTP<\/samp><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u548c\u7c7b\u652f\u6301\u8fd9\u4e9b\u5143\u7d20\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><samp>HttpRequest<\/samp><samp>HttpResponse<\/samp><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Http\u8bf7\u6c42\n<ul class=\"wp-block-list\">\n<li>HTTP \u8bf7\u6c42\u7c7b\u578b\uff0c\u4f8b\u5982 GET\u3001POST\u3001PATCH\u3001PUT\u3001DELETE\u3001TRACE\u3001 \u8fde\u63a5\u3001\u5934\u90e8\u548c\u9009\u9879<\/li>\n\n\n\n<li>\u8bf7\u6c42\u6807\u5934\uff08\u5982\u679c\u9700\u8981\uff09<\/li>\n\n\n\n<li>\u8bfb\u53d6\u548c\u8fde\u63a5\u8d85\u65f6<\/li>\n\n\n\n<li>\u5fc5\u8981\u65f6\u91cd\u5b9a\u5411<\/li>\n\n\n\n<li>\u90ae\u4ef6\u6b63\u6587\u7684\u5185\u5bb9<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li><samp>HttpResponse<\/samp>\n<ul class=\"wp-block-list\">\n<li>HTTP \u72b6\u6001\u4ee3\u7801<\/li>\n\n\n\n<li>\u54cd\u5e94\u6807\u5934\uff08\u5982\u679c\u9700\u8981\uff09<\/li>\n\n\n\n<li>\u54cd\u5e94\u6b63\u6587\u7684\u5185\u5bb9<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u5411\u5916\u90e8\u670d\u52a1\u5668\u53d1\u51fa HTTP GET \u8bf7\u6c42\uff0c\u8be5\u8bf7\u6c42\u4f20\u9012\u7ed9\u53c2\u6570\u4e2d\u7684\u65b9\u6cd5\u3002\u6b64\u793a\u4f8b\u8fd8\u8bbf\u95ee \u8fd4\u56de\u7684\u54cd\u5e94\u3002<samp>getCalloutResponseContents<\/samp><var>url<\/var><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class HttpCalloutSample {\n\n  \/\/ Pass in the endpoint to be used using the string url\n  public String getCalloutResponseContents(String url) {\n\n    \/\/ Instantiate a new Http object\n    Http h = new Http();\n\n     \/\/ Instantiate a new HTTP request, specify the method (GET) as well as the endpoint\n    HttpRequest req = new HttpRequest();\n    req.setEndpoint(url);\n    req.setMethod('GET');\n\n    \/\/ Send the request, and return a response\n    HttpResponse res = h.send(req);\n    return res.getBody();\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"asyncCallout\">\u524d\u9762\u7684\u793a\u4f8b\u662f\u540c\u6b65\u8fd0\u884c\u7684\uff0c\u8fd9\u610f\u5473\u7740\u6ca1\u6709\u8fdb\u4e00\u6b65\u7684\u5904\u7406 \u5728\u5916\u90e8 Web \u670d\u52a1\u8fd4\u56de\u54cd\u5e94\u4e4b\u524d\u53d1\u751f\u3002\u6216\u8005\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u00a0@future\u6ce8\u89e3\uff0c\u4f7f \u6807\u6ce8\u5f02\u6b65\u8fd0\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u5411\u5916\u90e8\u670d\u52a1\u5668\u53d1\u51fa HTTP POST \u8bf7\u6c42\uff0c\u8be5\u8bf7\u6c42\u4f20\u9012\u7ed9\u53c2\u6570\u4e2d\u7684\u65b9\u6cd5\u3002\u66ff\u6362\u4e3a \u8981\u5728\u6807\u6ce8\u4e2d\u53d1\u9001\u7684 JSON \u5185\u5bb9\u3002<samp>getPostCalloutResponseContents<\/samp><var>url<\/var><var>Your_JSON_Content<\/var><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class HttpPostCalloutSample {\n\n  \/\/ Pass in the endpoint to be used using the string url\n  public String getPostCalloutResponseContents(String url) {\n\n    \/\/ Instantiate a new Http object\n    Http h = new Http();\n\n    \/\/ Instantiate a new HTTP request\n    \/\/ Specify request properties such as the endpoint, the POST method, etc. \n    HttpRequest req = new HttpRequest();\n    req.setEndpoint(url);\n    req.setMethod('POST');\n    req.setHeader('Content-Type', 'application\/json');\n    req.setBody('{<em>Your_JSON_Content<\/em>}');\n\n    \/\/ Send the request, and return a response\n    HttpResponse res = h.send(req);\n    return res.getBody();\n  }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u4ece\u7ec8\u7ed3\u70b9\u6216\u91cd\u5b9a\u5411\u7ec8\u7ed3\u70b9\u8bbf\u95ee\u5916\u90e8\u670d\u52a1\u5668\uff0c\u8bf7\u6dfb\u52a0\u8fdc\u7a0b\u7ad9\u70b9 \u6dfb\u52a0\u5230\u6388\u6743\u8fdc\u7a0b\u7ad9\u70b9\u7684\u5217\u8868\u4e2d\u3002\u767b\u5f55\u5230 Salesforce\uff0c\u7136\u540e\u4ece\u201c\u8bbe\u7f6e\u201d\u7684\u201c\u5feb\u901f\u201d\u4e2d \u201c\u67e5\u627e\u201d\u6846\uff0c\u8f93\u5165 \uff0c\u7136\u540e\u9009\u62e9<strong>\u201c\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e<\/strong>\u201d\u3002<kbd>Remote Site Settings<\/kbd><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4f7f\u7528 XML \u7c7b\u6216 JSON\u00a0\u7c7b\u6765\u89e3\u6790\u00a0XML\u00a0\u6216 JSON \u4e2d\u7684\u5185\u5bb9 \u7531\u00a0<samp>HttpRequest<\/samp>\u00a0\u521b\u5efa\u7684\u8bf7\u6c42\u7684\u6b63\u6587\uff0c\u6216<samp>\u7531 HttpResponse<\/samp>\u00a0\u8bbf\u95ee\u7684\u54cd\u5e94\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u8003\u8651<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>AJAX \u4ee3\u7406\u5904\u7406\u91cd\u5b9a\u5411\u548c\u8eab\u4efd\u9a8c\u8bc1\u8d28\u8be2 \uff08401\/407 responses\uff09 \u81ea\u52a8\u3002\u6709\u5173 AJAX \u4ee3\u7406\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u00a0AJAX \u5de5\u5177\u5305 \u6587\u6863\u3002<\/li>\n\n\n\n<li>\u60a8\u53ef\u4ee5\u5c06\u7ec8\u7ed3\u70b9\u8bbe\u7f6e\u4e3a\u547d\u540d\u51ed\u636e URL\u3002\u547d\u540d\u51ed\u636e URL \u5305\u542b\u65b9\u6848\uff0c\u540d\u79f0 \u547d\u540d\u51ed\u636e\u548c\u53ef\u9009\u8def\u5f84\u3002\u4f8b\u5982\uff1a\u3002\u4e00\u4e2a\u547d\u540d\u7684 credential \u6307\u5b9a\u6807\u6ce8\u7aef\u70b9\u7684 URL \u53ca\u5176\u6240\u9700\u7684 URL \u4e00\u4e2a\u5b9a\u4e49\u4e2d\u7684\u8eab\u4efd\u9a8c\u8bc1\u53c2\u6570\u3002Salesforce \u7ba1\u7406\u6240\u6709 \u5bf9\u6307\u5b9a\u547d\u540d\u51ed\u636e\u4f5c\u4e3a\u6807\u6ce8\u7684 Apex \u6807\u6ce8\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1 \u7aef\u70b9\uff0c\u8fd9\u6837\u60a8\u7684\u4ee3\u7801\u5c31\u4e0d\u5fc5\u8fd9\u6837\u505a\u4e86\u3002\u60a8\u8fd8\u53ef\u4ee5\u8df3\u8fc7\u8fdc\u7a0b\u7ad9\u70b9 \u8bbe\u7f6e\uff0c\u5426\u5219\uff0c\u5411\u5916\u90e8\u7ad9\u70b9\u8fdb\u884c\u6807\u6ce8\u65f6\u9700\u8981\u8fd9\u4e9b\u8bbe\u7f6e\uff0c\u7528\u4e8e \u547d\u540d\u51ed\u636e\u4e2d\u5b9a\u4e49\u7684\u7ad9\u70b9\u3002\u8bf7\u53c2\u9605\u4f5c\u4e3a\u6807\u6ce8\u7684\u547d\u540d\u51ed\u636e \u7aef\u70b9\u3002<samp>callout:callout:My_Named_Credential\/some_path<\/samp><\/li>\n\n\n\n<li>\u5728\u6807\u6ce8\u4e2d\u8bbe\u7f6e\u8bf7\u6c42\u6b63\u6587\u65f6\uff0c\u8bf7\u5c06\u65b9\u6cd5\u8bbe\u7f6e\u4e3a \u3002\u5982\u679c\u8bbe\u7f6e\u4e86\u8bf7\u6c42\u6b63\u6587\u548c\u8bf7\u6c42 \u65b9\u6cd5\u4e3a \uff0c\u5219\u6267\u884c\u8bf7\u6c42\u3002<samp>POST<\/samp><samp>GET<\/samp><samp>POST<\/samp><\/li>\n\n\n\n<li>\u5982\u679c\u60a8\u6709\u6765\u81ea DML \u7684\u5f85\u5904\u7406\u672a\u63d0\u4ea4\u4ea4\u6613\uff0c\u5219\u4f1a\u963b\u6b62\u6807\u6ce8 \u64cd\u4f5c\u3001\u53ef\u6392\u961f\u4f5c\u4e1a\uff08\u4e0e \u3001 \u6216\u5c06\u6765\u7684\u65b9\u6cd5\u4e00\u8d77\u6392\u961f\uff09\u3002<samp>System.enqueueJob<\/samp><samp>Database.executeBatch<\/samp><\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">\u6d4b\u8bd5 HTTP \u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u90e8\u7f72\u6216\u6253\u5305 Apex\uff0c75% \u7684\u4ee3\u7801\u5fc5\u987b\u5177\u6709\u6d4b\u8bd5\u8986\u76d6\u7387\u3002\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0ctest \u65b9\u6cd5\u4e0d\u652f\u6301 HTTP \u6807\u6ce8\uff0c\u56e0\u6b64\u6267\u884c\u6807\u6ce8\u7684\u6d4b\u8bd5\u4f1a\u5931\u8d25\u3002\u542f\u7528 HTTP \u901a\u8fc7\u6307\u793a Apex \u5728\u6d4b\u8bd5\u4e2d\u751f\u6210\u6a21\u62df\u54cd\u5e94\u6765\u8fdb\u884c\u6807\u6ce8\u6d4b\u8bd5\uff0c\u4f7f\u7528 .<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><samp>Test.setMock<\/samp>\u901a\u8fc7\u4ee5\u4e0b\u65b9\u5f0f\u4e4b\u4e00\u6307\u5b9a\u6a21\u62df\u54cd\u5e94\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u901a\u8fc7\u5b9e\u73b0\u00a0<samp>HttpCalloutMock<\/samp>\u00a0\u63a5\u53e3<\/li>\n\n\n\n<li>\u901a\u8fc7\u5c06\u9759\u6001\u8d44\u6e90\u4e0e StaticResourceCalloutMock \u6216\u00a0<samp>MultiStaticResourceCalloutMock<\/samp>\u00a0\u4e00\u8d77\u4f7f\u7528<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u7684\u6a21\u62df\u6807\u6ce8\u4e4b\u524d\u542f\u7528\u8fd0\u884c DML \u64cd\u4f5c\uff0c\u8bf7\u53c2\u9605\u6267\u884c DML \u64cd\u4f5c\u548c\u6a21\u62df\u6807\u6ce8\u3002<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>\u901a\u8fc7\u5b9e\u73b0 HttpCalloutMock \u63a5\u53e3\u6d4b\u8bd5 HTTP \u6807\u6ce8<\/strong><\/li>\n\n\n\n<li><strong>\u4f7f\u7528\u9759\u6001\u8d44\u6e90\u6d4b\u8bd5 HTTP \u6807\u6ce8<\/strong><\/li>\n\n\n\n<li><strong>\u6267\u884c DML \u64cd\u4f5c\u548c\u6a21\u62df\u6807\u6ce8<\/strong><\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">\u901a\u8fc7\u5b9e\u73b0&nbsp;HttpCalloutMock&nbsp;\u63a5\u53e3\u6d4b\u8bd5 HTTP \u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e3a\u63a5\u53e3\u63d0\u4f9b\u4e00\u4e2a\u5b9e\u73b0\uff0c\u4ee5\u6307\u5b9a Apex \u8fd0\u884c\u65f6\u8c03\u7528\u7684\u65b9\u6cd5\u4e2d\u53d1\u9001\u7684\u54cd\u5e94 \u53d1\u9001\u6807\u6ce8\u7684\u54cd\u5e94\u3002<samp>HttpCalloutMock<\/samp><samp>respond<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>global class <em>YourHttpCalloutMockImpl<\/em> implements HttpCalloutMock {\n    global HTTPResponse respond(HTTPRequest req) {\n        \/\/ Create a fake response.\n        \/\/ Set response values, and \n        \/\/ return response.\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5b9e\u73b0\u63a5\u53e3\u7684\u7c7b\u53ef\u4ee5\u662f\u5168\u5c40\u7c7b\uff0c\u4e5f\u53ef\u4ee5\u662f\u516c\u5171\u7c7b\u3002<samp>HttpCalloutMock<\/samp><\/li>\n\n\n\n<li>\u60a8\u53ef\u4ee5\u4f7f\u7528<samp>@isTest<\/samp>\u6ce8\u91ca\u6b64\u7c7b\uff0c\u56e0\u4e3a\u5b83\u5c06\u4ec5\u5728\u6d4b\u8bd5\u4e0a\u4e0b\u6587\u4e2d\u4f7f\u7528\u3002 \u8fd9\u6837\uff0c\u5c31\u53ef\u4ee5\u5c06\u5176\u4ece\u7ec4\u7ec7\u7684\u4ee3\u7801\u5927\u5c0f\u4e2d\u6392\u9664 \u9650\u5236\u4e3a 6 MB\u3002<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u73b0\u5728\uff0c\u60a8\u5df2\u7ecf\u6307\u5b9a\u4e86\u5047\u54cd\u5e94\u7684\u503c\uff0c\u8bf7\u6307\u793a Apex \u8fd0\u884c\u65f6\u901a\u8fc7\u8c03\u7528\u6d4b\u8bd5\u65b9\u6cd5\u53d1\u9001\u6b64\u865a\u5047\u54cd\u5e94\u3002\u5bf9\u4e8e\u7b2c\u4e00\u4e2a\u53c2\u6570\uff0c\u4f20\u9012 \uff0c\u5bf9\u4e8e\u7b2c\u4e8c\u4e2a\u53c2\u6570 \u53c2\u6570\uff0c\u5219\u4f20\u9012 \u7684\u63a5\u53e3\u5b9e\u73b0\u7684\u65b0\u5b9e\u4f8b\uff0c\u5982\u4e0b\u6240\u793a\uff1a<samp>Test.setMock<\/samp><samp>HttpCalloutMock.class<\/samp><samp>HttpCalloutMock<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Test.setMock(HttpCalloutMock.class, new <em>YourHttpCalloutMockImpl<\/em>());<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6b64\u4e4b\u540e\uff0c\u5982\u679c\u5728\u6d4b\u8bd5\u4e0a\u4e0b\u6587\u4e2d\u8c03\u7528 HTTP \u6807\u6ce8\uff0c\u5219\u6807\u6ce8\u4e0d\u4f1a made \u65f6\uff0c\u60a8\u4f1a\u6536\u5230\u5728\u65b9\u6cd5\u5b9e\u73b0\u4e2d\u6307\u5b9a\u7684\u6a21\u62df\u54cd\u5e94\u3002<var>respond<\/var><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6267\u884c\u6807\u6ce8\u7684\u4ee3\u7801\u4f4d\u4e8e\u6258\u7ba1\u5305\u4e2d\uff0c\u5219\u8981\u6a21\u62df\u6807\u6ce8\uff0c \u4ece \u6d4b\u8bd5\u65b9\u6cd5\u8c03\u7528 \u5177\u6709\u76f8\u540c\u547d\u540d\u7a7a\u95f4\u7684\u76f8\u540c\u5305\u3002<samp>Test.setMock<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u6f14\u793a\u5982\u4f55\u6d4b\u8bd5 HTTP \u6807\u6ce8\u3002\u754c\u9762 \u5b9e\u73b0 \uff08\uff09 \u5217\u5728\u6700\u524d\u9762\u3002\u5b83\u540e\u9762\u662f\u4e00\u4e2a\u5305\u542b\u6d4b\u8bd5\u65b9\u6cd5\u7684\u7c7b\u548c\u53e6\u4e00\u4e2a \u5305\u542b\u6d4b\u8bd5\u8c03\u7528\u7684\u65b9\u6cd5\u3002\u6d4b\u8bd5\u65b9\u6cd5\u901a\u8fc7\u5728\u8c03\u7528\u4e4b\u524d\u8c03\u7528\u6765\u8bbe\u7f6e\u6a21\u62df\u6807\u6ce8\u6a21\u5f0f\u3002\u7136\u540e\uff0c\u5b83\u4f1a\u9a8c\u8bc1 \u8fd4\u56de\u7684\u54cd\u5e94\u662f\u5df2\u5b9e\u73b0\u7684\u65b9\u6cd5\u53d1\u9001\u7684\u54cd\u5e94\u3002\u5355\u72ec\u4fdd\u5b58\u6bcf\u4e2a\u7c7b\uff0c\u5e76\u5728 \u4e2d\u8fd0\u884c\u6d4b\u8bd5\u3002<samp>MockHttpResponseGenerator<\/samp><samp>testCallout<\/samp><samp>Test.setMock<\/samp><samp>getInfoFromExternalService<\/samp><samp>respond<\/samp><samp>CalloutClassTest<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nglobal class MockHttpResponseGenerator implements HttpCalloutMock {\n    \/\/ Implement this interface method\n    global HTTPResponse respond(HTTPRequest req) {\n        \/\/ Optionally, only send a mock response for a specific endpoint\n        \/\/ and method.\n        System.assertEquals('https:\/\/example.com\/example\/test', req.getEndpoint());\n        System.assertEquals('GET', req.getMethod());\n        \n        \/\/ Create a fake response\n        HttpResponse res = new HttpResponse();\n        res.setHeader('Content-Type', 'application\/json');\n        res.setBody('{\"example\":\"test\"}');\n        res.setStatusCode(200);\n        return res;\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CalloutClass {\n    public static HttpResponse getInfoFromExternalService() {\n        HttpRequest req = new HttpRequest();\n        req.setEndpoint('https:\/\/example.com\/example\/test');\n        req.setMethod('GET');\n        Http h = new Http();\n        HttpResponse res = h.send(req);\n        return res;\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nprivate class CalloutClassTest {\n     @isTest static void testCallout() {\n        \/\/ Set mock callout class \n        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());\n        \n        \/\/ Call method to test.\n        \/\/ This causes a fake response to be sent\n        \/\/ from the class that implements HttpCalloutMock. \n        HttpResponse res = CalloutClass.getInfoFromExternalService();\n        \n        \/\/ Verify response received contains fake values\n        String contentType = res.getHeader('Content-Type');\n        System.assert(contentType == 'application\/json');\n        String actualValue = res.getBody();\n        String expectedValue = '{\"example\":\"test\"}';\n        System.assertEquals(actualValue, expectedValue);\n        System.assertEquals(200, res.getStatusCode());\n    }\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528\u9759\u6001\u8d44\u6e90\u6d4b\u8bd5 HTTP \u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u901a\u8fc7\u6307\u5b9a \u60a8\u5e0c\u671b\u5728\u9759\u6001\u8d44\u6e90\u4e2d\u63a5\u6536\u7684\u54cd\u5e94\uff0c\u5e76\u4f7f\u7528 \u4e24\u4e2a\u5185\u7f6e\u7c7b\u4e4b\u4e00 &#8211; StaticResourceCalloutMock \u6216\u00a0<samp>MultiStaticResourceCalloutMock<\/samp>\u3002<a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_classes_restful_http_testing_static.htm#MultiStaticSection\"><\/a><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>\u4f7f\u7528&nbsp;StaticResourceCalloutMock&nbsp;\u6d4b\u8bd5 HTTP \u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u63d0\u4f9b\u4e86\u5185\u7f6e\u7c7b\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u9759\u6001\u4e2d\u6307\u5b9a\u54cd\u5e94\u6b63\u6587\u6765\u6d4b\u8bd5\u6807\u6ce8 \u8d44\u6e90\u3002\u4f7f\u7528\u6b64\u7c7b\u65f6\uff0c\u60a8\u4e0d\u5fc5\u63d0\u4f9b\u81ea\u5df1\u7684 \u63a5\u53e3\u7684\u5b9e\u73b0\u3002\u76f8\u53cd\uff0c\u53ea\u9700\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b\u5e76\u8bbe\u7f6e\u9759\u6001\u8d44\u6e90\u4ee5\u7528\u4e8e \u54cd\u5e94\u6b63\u6587\u4ee5\u53ca\u5176\u4ed6\u54cd\u5e94\u5c5e\u6027\uff0c\u5982\u72b6\u6001\u4ee3\u7801\u548c \u5185\u5bb9\u7c7b\u578b\u3002<samp>StaticResourceCalloutMock<\/samp><samp>HttpCalloutMock<\/samp><samp>StaticResourceCalloutMock<\/samp>\u9996\u5148\uff0c\u5fc5\u987b\u4ece\u8981\u5305\u542b\u7684\u6587\u672c\u6587\u4ef6\u521b\u5efa\u9759\u6001\u8d44\u6e90 \u54cd\u5e94\u6b63\u6587\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u521b\u5efa\u4e00\u4e2a\u5305\u542b\u8981\u8fd4\u56de\u7684\u54cd\u5e94\u6b63\u6587\u7684\u6587\u672c\u6587\u4ef6\u3002 \u54cd\u5e94\u6b63\u6587\u53ef\u4ee5\u662f\u4efb\u610f\u5b57\u7b26\u4e32\uff0c\u4f46\u5b83\u5fc5\u987b\u4e0e \u5185\u5bb9\u7c7b\u578b\uff08\u5982\u679c\u6307\u5b9a\uff09\u3002\u4f8b\u5982\uff0c\u5982\u679c\u60a8\u7684\u56de\u590d\u6ca1\u6709\u5185\u5bb9 \u6307\u5b9a\u7c7b\u578b\uff0c\u5219\u8be5\u6587\u4ef6\u53ef\u4ee5\u5305\u542b\u4efb\u610f\u5b57\u7b26\u4e32\u3002\u5982\u679c\u6307\u5b9a application\/json \u7684\u5185\u5bb9\u7c7b\u578b \u5bf9\u4e8e\u54cd\u5e94\uff0c\u6587\u4ef6\u5185\u5bb9\u5e94\u4e3a JSON \u5b57\u7b26\u4e32\uff0c\u4f8b\u5982 {\u201c\u5475\u5475\u201d\uff1a\u201c\u9a97\u4e86\u4f60\u201d}\u3002<kbd>abc<\/kbd><\/li>\n\n\n\n<li>\u4e3a\u6587\u672c\u6587\u4ef6\u521b\u5efa\u9759\u6001\u8d44\u6e90\uff1a\n<ol class=\"wp-block-list\" style=\"list-style-type:lower-alpha\">\n<li>\u5728\u201c\u8bbe\u7f6e\u201d\u4e2d\uff0c\u8f93\u5165\u201c\u5feb\u901f\u67e5\u627e\u201d\u6846\uff0c\u7136\u540e\u9009\u62e9\u201c<strong>\u9759\u6001\u8d44\u6e90<\/strong>\u201d\u3002<kbd>Static Resources<\/kbd><\/li>\n\n\n\n<li>\u5355\u51fb<strong>\u201c\u65b0\u5efa<\/strong>\u201d\u3002<\/li>\n\n\n\n<li>\u4e3a\u9759\u6001\u8d44\u6e90\u547d\u540d\u3002<\/li>\n\n\n\n<li>\u9009\u62e9\u8981\u4e0a\u4f20\u7684\u6587\u4ef6\u3002<\/li>\n\n\n\n<li>\u70b9\u51fb<strong>\u4fdd\u5b58<\/strong>\u3002<\/li>\n<\/ol>\n<\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4e86\u89e3\u6709\u5173\u9759\u6001\u8d44\u6e90\u7684\u66f4\u591a\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605 Salesforce \u8054\u673a\u5e2e\u52a9\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b\u5e76\u8bbe\u7f6e\u9759\u6001\u8d44\u6e90\uff0c\u7136\u540e \u4efb\u4f55\u5176\u4ed6\u5c5e\u6027\u3002<samp>StaticResourceCalloutMock<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>StaticResourceCalloutMock mock = new StaticResourceCalloutMock();\nmock.setStaticResource('myStaticResourceName');\nmock.setStatusCode(200);\nmock.setHeader('Content-Type', 'application\/json');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\uff0c\u8c03\u7528\u4ee5\u8bbe\u7f6e\u6a21\u62df\u6807\u6ce8\u6a21\u5f0f\u5e76\u5c06\u5176\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u4f20\u9012 \u53c2\u6570\uff0c\u4ee5\u53ca\u60a8\u4e3a\u5176\u521b\u5efa\u7684\u7b2c\u4e8c\u4e2a\u53d8\u91cf\u540d\u79f0 \u8bba\u70b9\u3002<samp>Test.setMock<\/samp><samp>HttpCalloutMock.class<\/samp><samp>StaticResourceCalloutMock<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Test.setMock(HttpCalloutMock.class, <em>mock<\/em>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6b64\u4e4b\u540e\uff0c\u5982\u679c\u60a8\u7684\u6d4b\u8bd5\u65b9\u6cd5\u6267\u884c\u6807\u6ce8\uff0c\u5219\u4e0d\u4f1a\u8fdb\u884c\u6807\u6ce8\uff0c\u5e76\u4e14 Apex \u8fd0\u884c\u65f6\u53d1\u9001\u60a8\u5728 \u5b9e\u4f8b\u4e2d\u6307\u5b9a\u7684\u6a21\u62df\u54cd\u5e94\u3002<samp>StaticResourceCalloutMock<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6267\u884c\u6807\u6ce8\u7684\u4ee3\u7801\u4f4d\u4e8e \u4e00\u4e2a\u6258\u7ba1\u5305\uff0c\u4ece \u6d4b\u8bd5\u65b9\u6cd5\u3002<samp>Test.setMock<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u5305\u542b\u6d4b\u8bd5\u65b9\u6cd5 \uff08\uff09 \u548c \u5b83\u6240\u6d4b\u8bd5\u7684\u65b9\u6cd5 \uff08\uff09 \u6267\u884c\u6807\u6ce8\u3002\u5728\u8fd0\u884c\u6b64\u793a\u4f8b\u4e4b\u524d\uff0c\u8bf7\u521b\u5efa \u540d\u4e3a based \u7684\u9759\u6001\u8d44\u6e90 \u5728\u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\u7684\u6587\u672c\u6587\u4ef6\u4e0a\u3002\u5355\u72ec\u4fdd\u5b58\u6bcf\u4e2a\u7c7b\uff0c\u5e76\u5728 \u4e2d\u8fd0\u884c\u6d4b\u8bd5\u3002<samp>testCalloutWithStaticResources<\/samp><samp>getInfoFromExternalService<\/samp><kbd>mockResponse<\/kbd><kbd>{\"hah\":\"fooled you\"}<\/kbd><samp>CalloutStaticClassTest<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CalloutStaticClass {\n    public static HttpResponse getInfoFromExternalService(String endpoint) {\n        HttpRequest req = new HttpRequest();\n        req.setEndpoint(endpoint);\n        req.setMethod('GET');\n        Http h = new Http();\n        HttpResponse res = h.send(req);\n        return res;\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nprivate class CalloutStaticClassTest {\n    @isTest static void testCalloutWithStaticResources() {\n        \/\/ Use StaticResourceCalloutMock built-in class to\n        \/\/ specify fake response and include response body \n        \/\/ in a static resource.\n        StaticResourceCalloutMock mock = new StaticResourceCalloutMock();\n        mock.setStaticResource('mockResponse');\n        mock.setStatusCode(200);\n        mock.setHeader('Content-Type', 'application\/json');\n        \n        \/\/ Set the mock callout mode\n        Test.setMock(HttpCalloutMock.class, mock);\n        \n        \/\/ Call the method that performs the callout\n        HTTPResponse res = CalloutStaticClass.getInfoFromExternalService(\n            'https:\/\/example.com\/example\/test');\n        \n        \/\/ Verify response received contains values returned by\n        \/\/ the mock response.\n        \/\/ This is the content of the static resource.\n        System.assertEquals('{\"hah\":\"fooled you\"}', res.getBody());\n        System.assertEquals(200,res.getStatusCode());\n        System.assertEquals('application\/json', res.getHeader('Content-Type'));   \n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>\u4f7f\u7528&nbsp;MultiStaticResourceCalloutMock&nbsp;\u6d4b\u8bd5 HTTP \u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Apex \u63d0\u4f9b\u4e86\u5185\u7f6e\u7c7b\uff0c\u60a8\u53ef\u4ee5\u901a\u8fc7\u5728\u9759\u6001\u4e2d\u6307\u5b9a\u54cd\u5e94\u6b63\u6587\u6765\u6d4b\u8bd5\u6807\u6ce8 \u8d44\u6e90\u3002\u6b64\u7c7b\u7c7b\u4f3c\u4e8e \u9664\u4e86\u5b83\u5141\u8bb8\u60a8\u6307\u5b9a \u591a\u4e2a\u54cd\u5e94\u673a\u6784\u3002\u4f7f\u7528\u6b64\u7c7b\u65f6\uff0c\u60a8\u4e0d\u5fc5\u63d0\u4f9b \u60a8\u81ea\u5df1\u7684\u63a5\u53e3\u5b9e\u73b0\u3002\u76f8\u53cd\uff0c\u53ea\u9700\u521b\u5efa\u4e00\u4e2a\u5b9e\u4f8b\u5e76\u5c06 \u6bcf\u4e2a\u7ec8\u7ed3\u70b9\u8981\u4f7f\u7528\u7684\u9759\u6001\u8d44\u6e90\u3002\u60a8\u8fd8\u53ef\u4ee5\u8bbe\u7f6e\u5176\u4ed6\u54cd\u5e94\u5c5e\u6027\uff0c\u4f8b\u5982 \u72b6\u6001\u4ee3\u7801\u548c\u5185\u5bb9\u7c7b\u578b\u3002<samp>MultiStaticResourceCalloutMock<\/samp><samp>StaticResourceCalloutMock<\/samp><samp>HttpCalloutMock<\/samp><samp>MultiStaticResourceCalloutMock<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\uff0c\u5fc5\u987b\u4ece\u6587\u672c\u6587\u4ef6\u521b\u5efa\u9759\u6001\u8d44\u6e90\u4ee5\u5305\u542b\u54cd\u5e94\u6b63\u6587\u3002\u8bf7\u53c2\u9605\u00a0\u4f7f\u7528\u00a0<samp>StaticResourceCalloutMock<\/samp>\u00a0\u6d4b\u8bd5 HTTP \u6807\u6ce8\u4e2d\u6982\u8ff0\u7684\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u521b\u5efa \u548c \u7684\u5b9e\u4f8b \u8bbe\u7f6e\u9759\u6001\u8d44\u6e90\u548c\u4efb\u4f55\u5176\u4ed6\u5c5e\u6027\u3002<samp>MultiStaticResourceCalloutMock<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>MultiStaticResourceCalloutMock multimock = new MultiStaticResourceCalloutMock();\nmultimock.setStaticResource('https:\/\/example.com\/example\/test', 'mockResponse');\nmultimock.setStaticResource('https:\/\/example.com\/example\/sfdc', 'mockResponse2');\nmultimock.setStatusCode(200);\nmultimock.setHeader('Content-Type', 'application\/json');<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\uff0c\u8c03\u7528\u4ee5\u8bbe\u7f6e\u6a21\u62df\u6807\u6ce8\u6a21\u5f0f\u5e76\u5c06\u5176\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u4f20\u9012 \u53c2\u6570\uff0c\u4ee5\u53ca\u60a8\u4e3a AS \u521b\u5efa\u7684\u53d8\u91cf\u540d\u79f0 \u7b2c\u4e8c\u4e2a\u53c2\u6570\u3002<samp>Test.setMock<\/samp><samp>HttpCalloutMock.class<\/samp><samp>MultiStaticResourceCalloutMock<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Test.setMock(HttpCalloutMock.class, <em>multimock<\/em>);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u6b64\u4e4b\u540e\uff0c\u5982\u679c\u6d4b\u8bd5\u65b9\u6cd5\u5bf9\u67d0\u4e2a\u7ec8\u7ed3\u70b9\u6267\u884c HTTP \u6807\u6ce8&nbsp;https:\/\/example.com\/example\/test&nbsp;\u6216&nbsp;https:\/\/example.com\/example\/sfdc\uff0c\u5219\u4e0d\u4f1a\u8fdb\u884c\u6807\u6ce8 \u5e76\u4e14 Apex \u8fd0\u884c\u65f6\u4f1a\u53d1\u9001\u60a8\u5728 \u7684\u5b9e\u4f8b\u3002<samp>MultiStaticResourceCalloutMock<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f\u4e00\u4e2a\u5b8c\u6574\u7684\u793a\u4f8b\uff0c\u5176\u4e2d\u5305\u542b\u6d4b\u8bd5\u65b9\u6cd5 \uff08\uff09 \u548c\u5b83\u6b63\u5728\u6d4b\u8bd5\u7684\u6267\u884c\u6807\u6ce8\u7684\u65b9\u6cd5 \uff08\uff09\u3002\u5728\u8fd0\u884c\u6b64\u793a\u4f8b\u4e4b\u524d\uff0c\u8bf7\u521b\u5efa \u540d\u4e3a based \u7684\u9759\u6001\u8d44\u6e90 \u5728\u4e00\u4e2a\u6587\u672c\u6587\u4ef6\u4e0a\uff0c\u5176\u4e2d\u5305\u542b\u5185\u5bb9\uff0c\u53e6\u4e00\u4e2a\u57fa\u4e8e \u5305\u542b\u4ee5\u4e0b\u5185\u5bb9\u7684\u6587\u672c\u6587\u4ef6\u3002\u5355\u72ec\u4fdd\u5b58\u6bcf\u4e2a\u7c7b\uff0c\u5e76\u5728 \u4e2d\u8fd0\u884c\u6d4b\u8bd5\u3002<samp>testCalloutWithMultipleStaticResources<\/samp><samp>getInfoFromExternalService<\/samp><kbd>mockResponse<\/kbd><kbd>{\"hah\":\"fooled you\"}<\/kbd><kbd>mockResponse2<\/kbd><kbd>{\"hah\":\"fooled you twice\"}<\/kbd><samp>CalloutMultiStaticClassTest<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class CalloutMultiStaticClass {\n    public static HttpResponse getInfoFromExternalService(String endpoint) {\n        HttpRequest req = new HttpRequest();\n        req.setEndpoint(endpoint);\n        req.setMethod('GET');\n        Http h = new Http();\n        HttpResponse res = h.send(req);\n        return res;\n    }\n}<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nprivate class CalloutMultiStaticClassTest {\n    @isTest static void testCalloutWithMultipleStaticResources() {\n        \/\/ Use MultiStaticResourceCalloutMock to\n        \/\/ specify fake response for a certain endpoint and \n        \/\/ include response body in a static resource.    \n        MultiStaticResourceCalloutMock multimock = new MultiStaticResourceCalloutMock();\n        multimock.setStaticResource(\n            'https:\/\/example.com\/example\/test', 'mockResponse');\n        multimock.setStaticResource(\n            'https:\/\/example.com\/example\/sfdc', 'mockResponse2');\n        multimock.setStatusCode(200);\n        multimock.setHeader('Content-Type', 'application\/json');\n        \n        \/\/ Set the mock callout mode\n        Test.setMock(HttpCalloutMock.class, multimock);\n        \n        \/\/ Call the method for the first endpoint\n        HTTPResponse res = CalloutMultiStaticClass.getInfoFromExternalService(\n            'https:\/\/example.com\/example\/test');\n        \/\/ Verify response received \n        System.assertEquals('{\"hah\":\"fooled you\"}', res.getBody());\n        \n        \/\/ Call the method for the second endpoint\n        HTTPResponse res2 = CalloutMultiStaticClass.getInfoFromExternalService(\n            'https:\/\/example.com\/example\/sfdc');\n        \/\/ Verify response received \n        System.assertEquals('{\"hah\":\"fooled you twice\"}', res2.getBody());\n    }\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u6267\u884c DML \u64cd\u4f5c\u548c\u6a21\u62df\u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u9ed8\u8ba4\u60c5\u51b5\u4e0b\uff0c\u6807\u6ce8\u4e0d\u662f \u5141\u8bb8\u5728\u540c\u4e00\u4e8b\u52a1\u4e2d\u6267\u884c DML \u64cd\u4f5c\u540e\uff0c\u56e0\u4e3a DML \u64cd\u4f5c \u5bfc\u81f4\u5f85\u5904\u7406\u7684\u672a\u63d0\u4ea4\u5de5\u4f5c\uff0c\u4ece\u800c\u963b\u6b62\u6807\u6ce8\u6267\u884c\u3002 \u6709\u65f6\uff0c\u60a8\u53ef\u80fd\u5e0c\u671b\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u63d2\u5165\u6d4b\u8bd5\u6570\u636e \u5728\u8fdb\u884c\u6807\u6ce8\u4e4b\u524d\u4f7f\u7528 DML\u3002\u8981\u542f\u7528\u6b64\u529f\u80fd\uff0c\u8bf7\u5c06\u90e8\u5206\u62ec\u8d77\u6765 \u5728 AND \u8bed\u53e5\u4e2d\u6267\u884c\u6807\u6ce8\u7684\u4ee3\u7801\u3002\u8bed\u53e5\u5fc5\u987b\u51fa\u73b0 \u5728\u58f0\u660e\u4e4b\u524d\u3002 \u6b64\u5916\uff0c\u5bf9 DML \u64cd\u4f5c\u7684\u8c03\u7528\u4e0d\u5f97\u662f \/ \u5757\u7684\u4e00\u90e8\u5206\u3002<samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><samp>Test.startTest<\/samp><samp>Test.setMock<\/samp><samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DML \u64cd\u4f5c \u5728\u6a21\u62df\u6807\u6ce8\u88ab\u5141\u8bb8\u4e14\u4e0d\u9700\u8981\u4e4b\u540e\u53d1\u751f \u6d4b\u8bd5\u65b9\u6cd5\u7684\u4efb\u4f55\u53d8\u5316\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">DML \u64cd\u4f5c\u652f\u6301\u9002\u7528\u4e8e\u6240\u6709\u5b9e\u73b0 \u4f7f\u7528\u63a5\u53e3\u548c\u9759\u6001\u8d44\u6e90\uff08\u6216 \uff09\u3002\u4ee5\u4e0b\u793a\u4f8b\u4f7f\u7528\u5df2\u5b9e\u73b0\u7684\u63a5\u53e3\uff0c\u4f46\u60a8 \u5728\u4f7f\u7528\u9759\u6001\u8d44\u6e90\u65f6\u53ef\u4ee5\u5e94\u7528\u76f8\u540c\u7684\u6280\u672f\u3002<samp>HttpCalloutMock<\/samp><samp>StaticResourceCalloutMock<\/samp><samp>MultiStaticResourceCalloutMock<\/samp><samp>HttpCalloutMock<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728\u6a21\u62df\u6807\u6ce8\u4e4b\u524d\u6267\u884c DML<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u57fa\u4e8e\u524d\u9762\u63d0\u4f9b\u7684\u00a0HttpCalloutMock\u00a0\u793a\u4f8b\u3002\u8be5\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u4f7f\u7528 \u548c \u8bed\u53e5\u6765\u5141\u8bb8 \u5728\u6a21\u62df\u6807\u6ce8\u4e4b\u524d\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\u6267\u884c\u7684 DML \u64cd\u4f5c\u3002 \u6d4b\u8bd5\u65b9\u6cd5\uff08\uff09\u9996\u5148\u63d2\u5165\u4e00\u4e2a\u6d4b\u8bd5\u5e10\u6237\uff0c\u8c03\u7528\uff0c\u4f7f\u7528\u8bbe\u7f6e\u6a21\u62df\u6807\u6ce8\u6a21\u5f0f\uff0c\u8c03\u7528\u4e00\u4e2a\u65b9\u6cd5 \u6267\u884c\u6807\u6ce8\uff0c\u9a8c\u8bc1\u6a21\u62df\u54cd\u5e94\u503c\uff0c\u6700\u540e \u8c03\u7528\u3002<samp>Test.startTestTest.stopTesttestCalloutTest.startTestTest.setMockTest.stopTest<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\nprivate class CalloutClassTest {\n     @isTest static void testCallout() {\n        \/\/ Perform some DML to insert test data\n        Account testAcct = new Account('Test Account');\n        insert testAcct;\n\n        \/\/ Call Test.startTest before performing callout\n        \/\/ but after setting test data.\n        Test.startTest();\n\n        \/\/ Set mock callout class \n        Test.setMock(HttpCalloutMock.class, new MockHttpResponseGenerator());\n        \n        \/\/ Call method to test.\n        \/\/ This causes a fake response to be sent\n        \/\/ from the class that implements HttpCalloutMock. \n        HttpResponse res = CalloutClass.getInfoFromExternalService();\n        \n        \/\/ Verify response received contains fake values\n        String contentType = res.getHeader('Content-Type');\n        System.assert(contentType == 'application\/json');\n        String actualValue = res.getBody();\n        String expectedValue = '{\"example\":\"test\"}';\n        System.assertEquals(actualValue, expectedValue);\n        System.assertEquals(200, res.getStatusCode());\n\n        Test.stopTest();\n    }\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5f02\u6b65\u9876\u70b9\u548c\u6a21\u62df\u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0e DML \u7c7b\u4f3c\uff0c\u5f02\u6b65 Apex \u64cd\u4f5c\u4f1a\u5bfc\u81f4\u6302\u8d77\u7684\u672a\u63d0\u4ea4\u5de5\u4f5c\uff0c\u4ece\u800c\u963b\u6b62 \u7a0d\u540e\u5728\u540c\u4e00\u4e8b\u52a1\u4e2d\u6267\u884c\u7684\u6807\u6ce8\u3002\u793a\u4f8b \u5f02\u6b65 Apex \u64cd\u4f5c\u662f\u5bf9\u672a\u6765\u65b9\u6cd5\u3001\u6279\u5904\u7406 Apex \u6216\u8ba1\u5212\u7684\u8c03\u7528 \u9876\u70b9\u3002\u8fd9\u4e9b\u5f02\u6b65\u8c03\u7528\u901a\u5e38\u5305\u542b\u5728\u6d4b\u8bd5\u65b9\u6cd5\u7684 and \u8bed\u53e5\u4e2d\uff0c\u4ee5\u4fbf \u5b83\u4eec\u5728 \u4e4b\u540e\u6267\u884c\u3002\u5728\u8fd9\u4e2a \u60c5\u51b5\u4e0b\uff0c\u53ef\u4ee5\u5728\u5f02\u6b65\u8c03\u7528\u540e\u6267\u884c\u6a21\u62df\u6807\u6ce8\uff0c\u5e76\u4e14\u4e0d\u4f1a\u8fdb\u884c\u4efb\u4f55\u66f4\u6539 \u5fc5\u8981\u3002\u4f46\u662f\uff0c\u5982\u679c\u5f02\u6b65\u8c03\u7528\u6ca1\u6709\u5305\u542b\u5728 and \u8bed\u53e5\u4e2d\uff0c\u4f60\u5c06\u5f97\u5230\u4e00\u4e2a \u5f02\u5e38\uff0c\u56e0\u4e3a\u672a\u63d0\u4ea4\u7684\u5de5\u4f5c\u5904\u4e8e\u5f85\u5904\u7406\u72b6\u6001\u3002\u8981\u9632\u6b62\u6b64\u5f02\u5e38\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u4efb\u4e00\u64cd\u4f5c \u5176\u4e2d\uff1a<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><samp>Test.stopTest<\/samp><samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5c06\u5f02\u6b65\u8c03\u7528\u5305\u542b\u5728 and \u8bed\u53e5\u4e2d\u3002<samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><code>Test.startTest(); MyClass.asyncCall(); Test.stopTest(); Test.setMock(..); \/\/ Takes two arguments MyClass.mockCallout();<\/code><\/li>\n\n\n\n<li>\u9075\u5faa\u4e0e DML \u8c03\u7528\u76f8\u540c\u7684\u89c4\u5219\uff1a\u5c06\u4ee3\u7801\u90e8\u5206\u62ec\u8d77\u6765 \u5728 AND \u8bed\u53e5\u4e2d\u6267\u884c\u6807\u6ce8\u3002\u8bed\u53e5\u5fc5\u987b\u51fa\u73b0\u5728\u8bed\u53e5\u4e4b\u524d\u3002\u6b64\u5916\uff0c \u5f02\u6b65\u8c03\u7528\u4e0d\u80fd\u662f \/ \u5757\u7684\u4e00\u90e8\u5206\u3002<samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><samp>Test.startTest<\/samp><samp>Test.setMock<\/samp><samp>Test.startTest<\/samp><samp>Test.stopTest<\/samp><code>MyClass.asyncCall(); Test.startTest(); Test.setMock(..); \/\/ Takes two arguments MyClass.mockCallout(); Test.stopTest();<\/code><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u6a21\u62df\u6807\u6ce8\u4e4b\u540e\u53d1\u751f\u7684\u5f02\u6b65\u8c03\u7528\u662f \u5141\u8bb8\u5e76\u4e14\u4e0d\u9700\u8981\u5bf9\u6d4b\u8bd5\u65b9\u6cd5\u8fdb\u884c\u4efb\u4f55\u66f4\u6539\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528\u8bc1\u4e66<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4f7f\u7528\u53cc\u5411 SSL \u8eab\u4efd\u9a8c\u8bc1\uff0c\u8bf7\u53d1\u9001\u4e00\u4e2a\u8bc1\u4e66\uff0c\u5176\u4e2d\u5305\u542b\u60a8\u7684\u6807\u6ce8\uff0c\u8be5\u8bc1\u4e66\u662f \u5728 Salesforce \u4e2d\u751f\u6210\u6216\u7531\u8bc1\u4e66\u9881\u53d1\u673a\u6784 \uff08CA\uff09 \u7b7e\u540d\u3002\u53d1\u9001\u8bc1\u4e66 \u589e\u5f3a\u4e86\u5b89\u5168\u6027\uff0c\u56e0\u4e3a\u6807\u6ce8\u7684\u76ee\u6807\u63a5\u6536\u8bc1\u4e66\u5e76\u53ef\u4ee5\u4f7f\u7528 \u5b83\u6839\u636e\u5176\u5bc6\u94a5\u5e93\u5bf9\u8bf7\u6c42\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u4e3a\u6807\u6ce8\u542f\u7528\u53cc\u5411 SSL \u8eab\u4efd\u9a8c\u8bc1\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u751f\u6210\u4e00\u4e2a \u8bc1\u4e66\u3002<\/li>\n\n\n\n<li>\u5c06\u8bc1\u4e66\u4e0e\u4ee3\u7801\u96c6\u6210\u3002\u8bf7\u53c2\u9605\u5bf9 SOAP \u670d\u52a1\u4f7f\u7528\u8bc1\u4e66\u548c\u5bf9\u00a0HTTP \u8bf7\u6c42\u4f7f\u7528\u8bc1\u4e66\u3002<\/li>\n\n\n\n<li>\u5982\u679c\u8981\u8fde\u63a5\u5230\u7b2c\u4e09\u65b9\u5e76\u4f7f\u7528\u81ea\u7b7e\u540d\u8bc1\u4e66\uff0c\u8bf7\u5171\u4eab Salesforce \u8bc1\u4e66\uff0c\u4ee5\u4fbf\u4ed6\u4eec\u53ef\u4ee5\u5c06\u8bc1\u4e66\u6dfb\u52a0\u5230\u4ed6\u4eec\u7684 \u5bc6\u94a5\u5e93\u3002\u5982\u679c\u8981\u8fde\u63a5\u5230\u7ec4\u7ec7\u5185\u7684\u5176\u4ed6\u5e94\u7528\u7a0b\u5e8f\uff0c \u914d\u7f6e Web \u670d\u52a1\u5668\u6216\u5e94\u7528\u7a0b\u5e8f\u670d\u52a1\u5668\u4ee5\u8bf7\u6c42\u5ba2\u6237\u7aef\u8bc1\u4e66\u3002\u8fd9 \u8fdb\u7a0b\u53d6\u51b3\u4e8e\u60a8\u4f7f\u7528\u7684 Web \u6216\u5e94\u7528\u7a0b\u5e8f\u670d\u52a1\u5668\u7684\u7c7b\u578b\u3002<\/li>\n\n\n\n<li>\u914d\u7f6e\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u00a0\u6807\u6ce8\u3002\u5728\u4efb\u4f55 Apex \u6807\u6ce8\u53ef\u4ee5\u8c03\u7528\u5916\u90e8\u7ad9\u70b9\u4e4b\u524d\uff0c\u8be5\u7ad9\u70b9\u5fc5\u987b \u5728\u201c\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u201d\u9875\u4e2d\u6ce8\u518c\uff0c\u5426\u5219\u6807\u6ce8\u5931\u8d25\u3002\u5982\u679c\u6807\u6ce8 \u6307\u5b9a\u547d\u540d\u51ed\u636e\u4f5c\u4e3a\u7ec8\u7ed3\u70b9\uff0c\u65e0\u9700\u914d\u7f6e\u8fdc\u7a0b \u7f51\u7ad9\u8bbe\u7f6e\u3002\u82e5\u8981\u8bbe\u7f6e\u547d\u540d\u51ed\u636e\uff0c\u8bf7\u53c2\u9605\u300a\u5b9a\u4e49\u547d\u540d\u51ed\u636e\u300b\u4e2d\u7684\u201c\u5b9a\u4e49\u547d\u540d\u51ed\u636e\u201d Salesforce \u5e2e\u52a9\u3002<\/li>\n<\/ol>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u751f\u6210\u8bc1\u4e66<\/li>\n\n\n\n<li>\u5c06\u8bc1\u4e66\u7528\u4e8e\u00a0SOAP \u670d\u52a1<br>\u8981\u652f\u6301\u5bf9 SOAP Web \u670d\u52a1\u7684\u6807\u6ce8\u8fdb\u884c\u53cc\u5411\u8eab\u4efd\u9a8c\u8bc1\uff0c\u8bf7\u5728 Salesforce \u4e2d\u751f\u6210\u8bc1\u4e66\u6216\u5c06\u5bc6\u94a5\u5bf9\u4ece\u5bc6\u94a5\u5e93\u5bfc\u5165 Salesforce\u3002\u7136\u540e\u5c06\u8bc1\u4e66\u4e0e\u60a8\u7684 Apex \u96c6\u6210\u3002<\/li>\n\n\n\n<li>\u5bf9 HTTP \u8bf7\u6c42\u4f7f\u7528\u8bc1\u4e66<\/li>\n<\/ol>\n\n\n\n<h1 class=\"wp-block-heading\">\u751f\u6210\u8bc1\u4e66<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u4f7f\u7528\u5728 Salesforce \u4e2d\u751f\u6210\u7684\u81ea\u7b7e\u540d\u8bc1\u4e66\u6216\u7531 \u8bc1\u4e66\u9881\u53d1\u673a\u6784 \uff08CA\uff09\u3002\u8981\u4e3a\u6807\u6ce8\u751f\u6210\u8bc1\u4e66\uff0c\u8bf7\u53c2\u9605\u751f\u6210\u8bc1\u4e66\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6210\u529f\u4fdd\u5b58 Salesforce \u8bc1\u4e66\u540e\uff0c\u8bc1\u4e66\u548c\u76f8\u5e94\u7684 \u5bc6\u94a5\u662f\u81ea\u52a8\u751f\u6210\u7684\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u521b\u5efa CA \u7b7e\u540d\u8bc1\u4e66\u540e\uff0c\u5fc5\u987b\u5148\u4e0a\u4f20\u7b7e\u540d\u8bc1\u4e66 \u4f60\u53ef\u4ee5\u4f7f\u7528\u5b83\u3002\u8bf7\u53c2\u9605\u201c\u751f\u6210\u7531\u8bc1\u4e66\u7b7e\u540d\u7684\u8bc1\u4e66 \u6743\u9650\u201c\u5728 Salesforce \u5728\u7ebf\u5e2e\u52a9\u4e2d\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u5c06\u8bc1\u4e66\u7528\u4e8e SOAP \u670d\u52a1<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u652f\u6301 SOAP Web Service \u6807\u6ce8\u7684\u53cc\u5411\u8eab\u4efd\u9a8c\u8bc1\uff0c\u8bf7\u751f\u6210 \u8bc1\u4e66\u6216\u5c06\u5bc6\u94a5\u5bf9\u4ece\u5bc6\u94a5\u5e93\u5bfc\u5165 Salesforce\u3002\u7136\u540e \u5c06\u8bc1\u4e66\u4e0e\u60a8\u7684 Apex \u96c6\u6210\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u91cd\u8981<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6211\u4eec\u5efa\u8bae\u5b58\u50a8\u5916\u90e8\u7684\u76f8\u4e92\u8eab\u4efd\u9a8c\u8bc1\u8bc1\u4e66 Java \u5bc6\u94a5\u5e93\u4e2d\u7684 Web \u670d\u52a1\u3002\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u8bc1\u4e66\u548c\u5bc6\u94a5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5c06\u8bc1\u4e66\u4e0e\u60a8\u7684 Apex \u96c6\u6210\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u4ece\u7b2c\u4e09\u65b9\u63a5\u6536 Web Service \u7684 WSDL\uff0c\u6216\u4ece \u8981\u8fde\u63a5\u5230\u7684\u5e94\u7528\u7a0b\u5e8f\u3002<\/li>\n\n\n\n<li>\u4ece Web \u670d\u52a1\u7684 WSDL \u751f\u6210 Apex \u7c7b\u3002\u8bf7\u53c2\u9605\u00a0SOAP \u670d\u52a1\uff1a\u4ece WSDL \u6587\u6863\u5b9a\u4e49\u7c7b\u3002<\/li>\n\n\n\n<li>\u751f\u6210\u7684 Apex \u7c7b\u5305\u62ec\u7528\u4e8e\u8c03\u7528\u7b2c\u4e09\u65b9 Web \u670d\u52a1\u7684\u5b58\u6839 \u7531 WSDL \u6587\u6863\u8868\u793a\u3002\u7f16\u8f91 Apex \u7c7b\uff0c\u5e76\u4e3a\u5b9e\u4f8b\u4e0a\u7684\u53d8\u91cf\u8d4b\u503c \u5b58\u6839\u7c7b\u3002\u8be5\u503c\u5fc5\u987b\u4e0e&nbsp;\u5728\u201c\u8bc1\u4e66\u548c\u5bc6\u94a5\u7ba1\u7406\u201d\u9875\u9762\u4e0a\u751f\u6210\u7684\u8bc1\u4e66\u3002<samp>clientCertName_x<\/samp><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u7f16\u8f91 Apex \u7c7b\uff0c\u5e76\u4f7f\u7528\u751f\u6210\u7684 WSDL2Apex \u4ee3\u7801\u4e2d\u7684\u793a\u4f8b WSDL\u00a0\u6587\u4ef6\u3002\u793a\u4f8b \u5047\u5b9a\u60a8\u751f\u6210\u7684\u8bc1\u4e66\u7684\u552f\u4e00\u540d\u79f0\u4e3a \u3002<samp>DocSampleCert<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docSample.DocSamplePort stub = new docSample.DocSamplePort();\nstub.clientCertName_x = 'DocSampleCert';\nString input = 'This is the input string';\nString output = stub.EchoString(input);<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u5bf9 HTTP \u8bf7\u6c42\u4f7f\u7528\u8bc1\u4e66<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Salesforce \u4e2d\u751f\u6210\u8bc1\u4e66\u540e\uff0c\u60a8\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u652f\u6301\u53cc\u5411 \u5bf9 HTTP \u8bf7\u6c42\u7684\u6807\u6ce8\u8fdb\u884c\u8eab\u4efd\u9a8c\u8bc1\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5c06\u8bc1\u4e66\u4e0e\u60a8\u7684 Apex \u96c6\u6210\uff0c\u8bf7\u6267\u884c\u4ee5\u4e0b\u64cd\u4f5c\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>\u751f\u6210\u8bc1\u4e66\u3002\u8bb0\u4e0b\u8bc1\u4e66\u7684\u552f\u4e00\u540d\u79f0\u3002<\/li>\n\n\n\n<li>\u5728 Apex \u4e2d\uff0c\u4f7f\u7528 \u7c7b\u3002\u7528\u4e8e\u53c2\u6570\u7684\u503c \u5bf9\u4e8e\u6b64\u65b9\u6cd5\uff0c\u5fc5\u987b\u4e0e\u8bc1\u4e66\u7684\u552f\u4e00\u540d\u79f0\u5339\u914d \u5728\u4e0a\u4e00\u6b65\u4e2d\u751f\u6210\u3002<samp>setClientCertificateName<\/samp><samp>HttpRequest<\/samp><\/li>\n<\/ol>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u793a\u4f8b\u6f14\u793a\u4e86\u4e0a\u4e00\u6b65\u7684\u6700\u540e\u4e00\u6b65 \u7a0b\u5e8f\u3002\u6b64\u793a\u4f8b\u5047\u5b9a\u60a8\u4e4b\u524d\u751f\u6210\u4e86\u4e00\u4e2a\u8bc1\u4e66&nbsp;\u552f\u4e00\u540d\u79f0\u4e3a \u3002<samp>DocSampleCert<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HttpRequest req = new HttpRequest();\nreq.setClientCertificateName('DocSampleCert');<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u6807\u6ce8\u9650\u5236\u548c\u5c40\u9650\u6027<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53 Apex \u4ee3\u7801\u5bf9 HTTP \u8bf7\u6c42\u8fdb\u884c\u6807\u6ce8\u65f6\uff0c\u5b58\u5728\u4ee5\u4e0b\u9650\u5236\u548c\u9650\u5236 \u6216 Web \u670d\u52a1\u8c03\u7528\u3002Web Service \u8c03\u7528\u53ef\u4ee5\u662f SOAP API \u8c03\u7528\uff0c\u4e5f\u53ef\u4ee5\u662f\u4efb\u4f55\u5916\u90e8 Web \u670d\u52a1\u8c03\u7528\u3002<a><\/a><\/p>\n\n\n\n<ul class=\"wp-block-list\" id=\"call_timeouts_summary\">\n<li>\u5355\u4e2a Apex \u4e8b\u52a1\u6700\u591a\u53ef\u4ee5\u5bf9 HTTP \u8bf7\u6c42\u6216 API \u53d1\u51fa 100 \u4e2a\u6807\u6ce8 \u53eb\u3002<\/li>\n\n\n\n<li>\u5728 Developer Edition \u7ec4\u7ec7\uff0c\u60a8\u6700\u591a\u53ea\u80fd\u5bf9\u5916\u90e8\u7684\u7aef\u70b9\u8fdb\u884c 20 \u4e2a\u5e76\u53d1\u6807\u6ce8 \u60a8\u7684 Salesforce \u7ec4\u7ec7\u7684\u57df\u3002\u6b64\u9650\u5236\u4e0d\u9002\u7528\u4e8e\u975e\u5f00\u53d1\u4eba\u5458\u7248 \u7ec4\u7ec7\u3002<\/li>\n\n\n\n<li>\u9ed8\u8ba4\u8d85\u65f6\u4e3a 10 \u79d2\u3002\u53ef\u4ee5\u4e3a\u6bcf\u4e2a\u6807\u6ce8\u5b9a\u4e49\u81ea\u5b9a\u4e49\u8d85\u65f6\u3002\u8fd9 \u6700\u5c0f\u503c\u4e3a 1 \u6beb\u79d2\uff0c\u6700\u5927\u503c\u4e3a 120,000 \u6beb\u79d2\u3002\u8bf7\u53c2\u9605 \u4e0b\u4e00\u8282\u4e86\u89e3\u5982\u4f55\u4e3a Web \u670d\u52a1\u6216 HTTP \u6807\u6ce8\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u8d85\u65f6\u3002<\/li>\n\n\n\n<li>\u5355\u4e2a Apex \u4e8b\u52a1\u7684\u6807\u6ce8\u7684\u6700\u5927\u7d2f\u79ef\u8d85\u65f6\u4e3a 120 \u79d2\u3002 \u6b64\u65f6\u95f4\u662f Apex \u4e8b\u52a1\u8c03\u7528\u7684\u6240\u6709\u6807\u6ce8\u7684\u7d2f\u52a0\u65f6\u95f4\u3002<\/li>\n\n\n\n<li>\u6bcf\u4e2a\u7ec4\u7ec7\u5bf9\u8fd0\u884c\u65f6\u95f4\u8d85\u8fc7 5 \u79d2\u7684\u957f\u65f6\u95f4\u8fd0\u884c\u8bf7\u6c42\u90fd\u6709\u9650\u5236\uff08\u603b\u8ba1 \u6267\u884c\u65f6\u95f4\uff09\u3002\u8ba1\u7b97\u6b64\u9650\u5236\u65f6\uff0c\u4e0d\u5305\u62ec HTTP \u6807\u6ce8\u5904\u7406\u65f6\u95f4\u3002 \u6211\u4eec\u6682\u505c\u6807\u6ce8\u7684\u8ba1\u65f6\u5668\uff0c\u5e76\u5728\u6807\u6ce8\u5b8c\u6210\u540e\u6062\u590d\u3002\u8bf7\u53c2\u9605 Lightning Platform Apex \u7684\u6267\u884c\u8c03\u63a7\u5668\u548c\u9650\u5236\u00a0\u9650\u5236\u3002<\/li>\n\n\n\n<li>\u5f53\u540c\u4e00\u4e8b\u52a1\u4e2d\u6709\u5f85\u5904\u7406\u7684\u64cd\u4f5c\u65f6\uff0c\u65e0\u6cd5\u8fdb\u884c\u6807\u6ce8\u3002 \u5bfc\u81f4\u6302\u8d77\u64cd\u4f5c\u7684\u5185\u5bb9\u662f DML \u8bed\u53e5\u3001\u5f02\u6b65 Apex\uff08\u4f8b\u5982 \u672a\u6765\u65b9\u6cd5\u548c\u6279\u5904\u7406 Apex \u4f5c\u4e1a\uff09\u3001\u8ba1\u5212\u7684 Apex \u6216\u53d1\u9001\u7535\u5b50\u90ae\u4ef6\u3002\u60a8\u53ef\u4ee5\u8fdb\u884c\u6807\u6ce8 \u5728\u6267\u884c\u8fd9\u4e9b\u7c7b\u578b\u7684\u64cd\u4f5c\u4e4b\u524d\u3002<\/li>\n\n\n\n<li>\u6302\u8d77\u7684\u64cd\u4f5c\u53ef\u80fd\u5728\u540c\u4e00\u4e8b\u52a1\u4e2d\u7684\u6a21\u62df\u6807\u6ce8\u4e4b\u524d\u53d1\u751f\u3002\u8bf7\u53c2\u9605\u5bf9\u57fa\u4e8e WSDL \u7684\u6807\u6ce8\u6267\u884c DML \u64cd\u4f5c\u548c\u6a21\u62df\u6807\u6ce8\u6216\u5bf9 HTTP \u6807\u6ce8\u6267\u884c DML \u64cd\u4f5c\u548c\u6a21\u62df\u6807\u6ce8\u3002<a href=\"https:\/\/developer.salesforce.com\/docs\/atlas.en-us.apexcode.meta\/apexcode\/apex_classes_restful_http_testing_dml.htm\"><\/a><\/li>\n\n\n\n<li>\u5f53\u6807\u5934\u6dfb\u52a0\u5230 \u6807\u6ce8\u8bf7\u6c42\u548c\u54cd\u5e94 \u672a\u7531\u5916\u90e8\u670d\u52a1\u5668\u8fd4\u56de\uff0c\u5219\u4f1a\u53d1\u751f\u8d85\u65f6\u3002<samp>Expect: 100-Continue<\/samp><samp>HTTP\/1.1 100 Continue<\/samp><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">\u53ea\u8bfb\u6a21\u5f0f\u4e0b\u7684 Apex \u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u53ea\u8bfb\u6a21\u5f0f\u4e0b\uff0c\u5916\u90e8\u670d\u52a1\u7684 Apex \u6807\u6ce8\u4f1a\u6267\u884c\uff0c\u5e76\u4e14\u4e0d\u4f1a\u88ab \u7cfb\u7edf\u3002\u901a\u5e38\uff0c\u60a8\u4f1a\u5728\u4ee5\u4e0b\u60c5\u51b5\u4e0b\u5728\u540c\u4e00\u4e8b\u52a1\u4e2d\u6267\u884c\u4e00\u4e9b\u540e\u7eed\u64cd\u4f5c \u63a5\u6536\u6765\u81ea\u6807\u6ce8\u7684\u54cd\u5e94\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u4ee5\u8fdb\u884c DML \u8c03\u7528\u4ee5\u66f4\u65b0 Salesforce \u8bb0\u5f55\u3002\u4f46 Salesforce \u4e2d\u7684\u5199\u5165\u64cd\u4f5c\uff08\u5982\u8bb0\u5f55\u66f4\u65b0\uff09\u88ab\u963b\u6b62 \u5728\u53ea\u8bfb\u6a21\u5f0f\u4e0b\u3002\u53ea\u8bfb\u6a21\u5f0f\u4e0b\u7684\u8fd9\u79cd\u884c\u4e3a\u4e0d\u4e00\u81f4\u53ef\u80fd\u4f1a\u7834\u574f \u7a0b\u5e8f\u6d41\u7a0b\u548c\u539f\u56e0\u95ee\u9898\u3002\u4e3a\u907f\u514d\u4e0d\u6b63\u786e\u7684\u7a0b\u5e8f\u884c\u4e3a\uff0c\u6211\u4eec\u5efa\u8bae\u60a8 \u9632\u6b62\u5728\u53ea\u8bfb\u6a21\u5f0f\u4e0b\u8fdb\u884c\u6807\u6ce8\u3002\u8981\u68c0\u67e5\u7ec4\u7ec7\u662f\u5426\u5904\u4e8e\u53ea\u8bfb\u6a21\u5f0f\uff0c \u53eb\u3002<samp>System.getApplicationReadWriteMode()<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u7684\u793a\u4f8b\u68c0\u67e5 \u7684\u8fd4\u56de\u503c\u3002\u5982\u679c\u8fd4\u56de\u503c\u7b49\u4e8e\u679a\u4e3e\u503c\uff0c\u5219\u7ec4\u7ec7 \u5728\u53ea\u8bfb\u6a21\u5f0f\u4e0b\uff0c\u5c06\u8df3\u8fc7\u6807\u6ce8\u3002\u5426\u5219 \uff08 value\uff09\uff0c\u5219\u6267\u884c\u6807\u6ce8\u3002<samp>System.getApplicationReadWriteMode()<\/samp><samp>ApplicationReadWriteMode.READ_ONLY<\/samp><samp>ApplicationReadWriteMode.DEFAULT<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u7c7b\u4f7f\u7528 Apex HTTP \u7c7b\u4f5c\u4e3a\u793a\u4f8b\u8fdb\u884c\u6807\u6ce8\u3002\u60a8\u8fd8\u53ef\u4ee5\u5236\u4f5c\u4e00\u4e2a \u901a\u8fc7 WSDL2Apex \u4f7f\u7528\u5bfc\u5165\u7684 WSDL \u8fdb\u884c\u6807\u6ce8\u3002\u68c0\u67e5\u53ea\u8bfb\u7684\u8fc7\u7a0b \u65e0\u8bba\u54ea\u79cd\u60c5\u51b5\uff0c\u6a21\u5f0f\u90fd\u662f\u76f8\u540c\u7684\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class HttpCalloutSampleReadOnly {\n    public class MyReadOnlyException extends Exception {}\n\n    \/\/ Pass in the endpoint to be used using the string url\n    public String getCalloutResponseContents(String url) {\n        \n        \/\/ Get Read-only mode status\n        ApplicationReadWriteMode mode = System.getApplicationReadWriteMode();\n        String returnValue = '';\n        \n        if (mode == ApplicationReadWriteMode.READ_ONLY) {\n            \/\/ Prevent the callout\n            throw new MyReadOnlyException('Read-only mode. Skipping callouts!');\n        } else if (mode == ApplicationReadWriteMode.DEFAULT) {\n            \/\/ Instantiate a new http object\n            Http h = new Http();\n            \n            \/\/ Instantiate a new HTTP request, specify the method (GET) \n            \/\/ as well as the endpoint.\n            HttpRequest req = new HttpRequest();\n            req.setEndpoint(url);\n            req.setMethod('GET');\n            \n            \/\/ Send the request, and return a response\n            HttpResponse res = h.send(req);\n            returnValue = res.getBody();                        \n        }\n        return returnValue;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u67d0\u4e9b Salesforce \u7ef4\u62a4\u6d3b\u52a8\u671f\u95f4\uff0c\u60a8\u7684 Salesforce \u7ec4\u7ec7\u5904\u4e8e\u53ea\u8bfb\u6a21\u5f0f\u3002 \u4f8b\u5982\u8ba1\u5212\u7684\u7ad9\u70b9\u5207\u6362\u548c\u5b9e\u4f8b\u5237\u65b0\u3002\u4f5c\u4e3a\u8fde\u7eed\u7ad9\u70b9\u5207\u6362\u7684\u4e00\u90e8\u5206\uff0c \u60a8\u7684 Salesforce \u7ec4\u7ec7\u5927\u7ea6\u6bcf\u516d\u4e2a\u6708\u5207\u6362\u5230\u4e00\u6b21\u5176\u5c31\u7eea\u7ad9\u70b9\u3002\u4e3a \u6709\u5173\u7ad9\u70b9\u5207\u6362\u7684\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u8fde\u7eed\u7ad9\u70b9\u5207\u6362\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8981\u5728\u6c99\u76d2\u4e2d\u6d4b\u8bd5\u53ea\u8bfb\u6a21\u5f0f\uff0c\u8bf7\u8054\u7cfb Salesforce \u4ee5\u542f\u7528\u53ea\u8bfb\u6a21\u5f0f\u6d4b\u8bd5 \u9009\u62e9\u3002\u542f\u7528\u6d4b\u8bd5\u9009\u9879\u540e\uff0c\u60a8\u53ef\u4ee5\u6253\u5f00\u53ea\u8bfb\u6a21\u5f0f\u5e76\u9a8c\u8bc1\u60a8\u7684 \u5e94\u7528\u7a0b\u5e8f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>\u8bbe\u7f6e\u6ce8\u89e3\u8d85\u65f6<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u7684\u793a\u4f8b\u4e3a Web \u670d\u52a1\u6807\u6ce8\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u8d85\u65f6\u3002\u8be5\u793a\u4f8b\u6709\u6548 \u66ff\u6362\u4e3a\u793a\u4f8b WSDL \u6587\u4ef6\u548c\u751f\u6210\u7684\u7c7b\uff0c\u5982\u751f\u6210\u7684 WSDL2Apex \u4ee3\u7801\u4e2d\u6240\u8ff0\u3002\u8bbe\u7f6e\u8d85\u65f6\u503c\uff08\u4ee5\u6beb\u79d2\u4e3a\u5355\u4f4d\uff09 \u4e3a\u7279\u6b8a\u53d8\u91cf\u8d4b\u503c \u5728 \u5b58\u6839\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><samp>DocSamplePort<\/samp><samp>timeout_x<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>docSample.DocSamplePort stub = new docSample.DocSamplePort();\nstub.timeout_x = 2000; \/\/ timeout in milliseconds<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u4e3a HTTP \u6807\u6ce8\u8bbe\u7f6e\u81ea\u5b9a\u4e49\u8d85\u65f6\u7684\u793a\u4f8b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>HttpRequest req = new HttpRequest();\nreq.setTimeout(2000); \/\/ timeout in milliseconds<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528\u5ef6\u7eed\u8fdb\u884c\u957f\u65f6\u95f4\u7684\u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\"><a><\/a>\u4f7f\u7528\u5f02\u6b65\u6807\u6ce8\u4ece Visualforce \u9875\u9762\u6216 Lightning \u7ec4\u4ef6\u5230\u5916\u90e8 Web \u670d\u52a1\uff0c\u5e76\u5728 \u56de\u8c03\u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f02\u6b65\u6807\u6ce8\u662f\u4ece Visualforce \u9875\u9762\u6216 Lightning \u5236\u4f5c\u7684\u6807\u6ce8 \u901a\u8fc7\u56de\u8c03\u65b9\u6cd5\u8fd4\u56de\u54cd\u5e94\u7684\u7ec4\u4ef6\u3002\u5f02\u6b65 \u6807\u6ce8\u4e5f\u79f0\u4e3a<dfn>\u5ef6\u7eed<\/dfn>\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Visualforce \u793a\u4f8b<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"async_diagram_intro\"><a><\/a>\u4e0b\u56fe\u663e\u793a\u4e86\u5f02\u6b65\u6807\u6ce8\u7684\u6267\u884c\u8def\u5f84\u3002 \u4ece Visualforce \u9875\u9762\u5f00\u59cb\u3002\u7528\u6237\u5728 Visualforce \u9875\u9762\u4e0a\u8c03\u7528\u4e00\u4e2a\u64cd\u4f5c\uff0c\u8be5\u64cd\u4f5c \u4ece Web \u670d\u52a1\u8bf7\u6c42\u4fe1\u606f\uff08\u6b65\u9aa4 1\uff09\u3002\u5e94\u7528\u670d\u52a1\u5668\u53d1\u51fa\u6807\u6ce8\u8bf7\u6c42 \u590d\u5236\u5230 Continuation \u670d\u52a1\u5668\uff0c\u7136\u540e\u8fd4\u56de\u5230 Visualforce \u9875\u9762\uff08\u6b65\u9aa4 2-3\uff09\u3002\u8fd9 Continuation \u670d\u52a1\u5668\u5c06\u8bf7\u6c42\u53d1\u9001\u5230 Web \u670d\u52a1\u5e76\u63a5\u6536\u54cd\u5e94\uff08\u6b65\u9aa4 4\u20137\uff09\uff0c\u7136\u540e\u5c06\u54cd\u5e94\u4ea4\u8fd8\u7ed9\u5e94\u7528\u670d\u52a1\u5668\uff08\u6b65\u9aa4 8\uff09\u3002\u6700\u540e\uff0c\u56de\u5e94 \u8fd4\u56de\u5230 Visualforce \u9875\u9762\uff08\u6b65\u9aa4 9\uff09\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a><\/a>\u5f02\u6b65\u6807\u6ce8\u7684\u6267\u884c\u6d41\u7a0b<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/developer.salesforce.com\/docs\/resources\/img\/en-us\/246.0?doc_id=dev_guides%2Fapex%2Fimages%2Fapex_continuations_diagram.png&amp;folder=apexcode\" alt=\"\u5ef6\u7eed\u7684\u6267\u884c\u6d41\u7a0b\u56fe\u793a\"\/><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\" id=\"async_case\"><a><\/a>\u53d7\u76ca\u4e8e\u5f02\u6b65\u6807\u6ce8\u7684\u5178\u578b Salesforce \u5e94\u7528\u7a0b\u5e8f \u5305\u542b\u4e00\u4e2a\u5e26\u6709\u6309\u94ae\u7684 Visualforce \u9875\u9762\u3002\u7528\u6237\u5355\u51fb\u8be5\u6309\u94ae\u53ef\u4ece \u5916\u90e8 Web \u670d\u52a1\u3002\u4f8b\u5982\uff0c\u83b7\u53d6 Web \u670d\u52a1\u4e2d\u7684\u67d0\u4e9b\u4ea7\u54c1\u3002\u7ec4\u7ec7\u4e2d\u6570\u4ee5\u5343\u8ba1\u7684\u4ee3\u7406\u53ef\u4ee5\u4f7f\u7528\u6b64\u529f\u80fd \u9875\u3002\u56e0\u6b64\uff0c\u4e00\u767e\u4e2a\u4ee3\u7406\u5546\u53ef\u4ee5\u70b9\u51fb\u540c\u4e00\u4e2a\u6309\u94ae\u6765\u5904\u7406\u4fdd\u4fee \u540c\u65f6\u63d0\u4f9b\u4ea7\u54c1\u4fe1\u606f\u3002\u8fd9\u4e00\u767e\u4e2a\u540c\u65f6\u52a8\u4f5c\u8d85\u8fc7\u4e86 \u5e76\u53d1\u957f\u65f6\u95f4\u8fd0\u884c\u8bf7\u6c42\u6570\u9650\u5236\u4e3a 10\u3002\u4f46\u662f\u901a\u8fc7\u4f7f\u7528\u5f02\u6b65\u6807\u6ce8\uff0c \u8bf7\u6c42\u4e0d\u53d7\u6b64\u9650\u5236\u7684\u7ea6\u675f\uff0c\u53ef\u4ee5\u6267\u884c\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u4ee5\u4e0b\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u4e2d\uff0c\u6309\u94ae\u64cd\u4f5c\u662f\u5728 Apex \u4e2d\u5b9e\u73b0\u7684 controller \u65b9\u6cd5\u3002action \u65b9\u6cd5\u521b\u5efa\u4e00\u4e2a\u5e76\u8fd4\u56de\u5b83\u3002\u5c06\u8bf7\u6c42\u53d1\u9001\u5230\u670d\u52a1\u540e\uff0c Visualforce \u8bf7\u6c42\u5df2\u6682\u505c\u3002\u7528\u6237\u5fc5\u987b\u7b49\u5f85\u8fd4\u56de\u54cd\u5e94\uff0c\u7136\u540e\u624d\u80fd\u8fd4\u56de \u7ee7\u7eed\u4f7f\u7528\u9875\u9762\u5e76\u8c03\u7528\u65b0\u64cd\u4f5c\u3002\u5f53\u5916\u90e8\u670d\u52a1\u8fd4\u56de \u54cd\u5e94\u65f6\uff0cVisualforce \u8bf7\u6c42\u5c06\u6062\u590d\uff0c\u9875\u9762\u5c06\u6536\u5230\u6b64\u54cd\u5e94\u3002<samp>Continuation<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f\u6211\u4eec\u793a\u4f8b\u5e94\u7528\u7a0b\u5e8f\u7684 Visualforce \u9875\u9762\u3002\u6b64\u9875\u9762\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u7528\u4e8e \u8c03\u7528\u63a7\u5236\u5668\u7684\u65b9\u6cd5 \u4e0e\u6b64\u9875\u9762\u76f8\u5173\u8054\u3002\u8fd4\u56de\u5ef6\u7eed\u7ed3\u679c\u5e76\u56de\u8c03\u540e \u65b9\u6cd5\uff0c\u6309\u94ae\u5c06\u518d\u6b21\u5448\u73b0\u7ec4\u4ef6\u4ee5\u663e\u793a\u54cd\u5e94\u7684\u4e3b\u4f53\u3002<samp>startRequest<\/samp><samp>outputText<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;apex:page controller=\"ContinuationController\" showChat=\"false\" showHeader=\"false\"&gt;\n   &lt;apex:form &gt;\n      &lt;!-- Invokes the action method when the user clicks this button. --&gt;\n      &lt;apex:commandButton action=\"{!startRequest}\" \n              value=\"Start Request\" reRender=\"result\"\/&gt; \n   &lt;\/apex:form&gt;\n\n   &lt;!-- This output text component displays the callout response body. --&gt;\n   &lt;apex:outputText id=\"result\" value=\"{!result}\" \/&gt;\n&lt;\/apex:page&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u4e0e Visualforce \u9875\u9762\u5173\u8054\u7684 Apex \u63a7\u5236\u5668\u3002\u8fd9 controller \u5305\u542b action \u548c callback \u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u8c03\u7528\u5916\u90e8\u670d\u52a1\u4e4b\u524d\uff0c\u5fc5\u987b\u5c06\u8fdc\u7a0b\u7ad9\u70b9\u6dfb\u52a0\u5230 Salesforce \u7528\u6237\u754c\u9762\u4e2d\u6388\u6743\u7684\u8fdc\u7a0b\u7ad9\u70b9\u3002\u5728\u201c\u8bbe\u7f6e\u201d\u4e2d\uff0c\u5728\u201c\u5feb\u901f\u67e5\u627e\u201d\u6846\u4e2d\u8f93\u5165\uff0c \uff0c\u7136\u540e\u9009\u62e9\u201c<strong>\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e<\/strong>\u201d\uff0c\u7136\u540e\u5355\u51fb\u201c<strong>\u65b0\u5efa\u201d \u8fdc\u7a0b\u7ad9\u70b9<\/strong>\u3002<kbd>Remote Site Settings<\/kbd><\/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 \u65e0\u9700\u914d\u7f6e\u8fdc\u7a0b\u7ad9\u70b9\u8bbe\u7f6e\u3002\u547d\u540d\u51ed\u636e\u6307\u5b9a URL \u4e00\u4e2a\u5b9a\u4e49\u4e2d\u7684\u6807\u6ce8\u7aef\u70b9\u53ca\u5176\u6240\u9700\u7684\u8eab\u4efd\u9a8c\u8bc1\u53c2\u6570\u3002\u8bbe\u7f6e \u547d\u540d\u51ed\u636e\uff0c\u8bf7\u53c2\u9605 Salesforce \u5e2e\u52a9\u4e2d\u7684\u201c\u5b9a\u4e49\u547d\u540d\u51ed\u636e\u201d\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\u4e00\u4e2a\u547d\u540d\u7684 credential URL \u5305\u542b\u65b9\u6848\u3001\u540d\u79f0 \u7684\u547d\u540d\u51ed\u636e\u548c\u53ef\u9009\u8def\u5f84\u3002\u4f8b\u5982\uff1a\u3002<samp>callout:<\/samp><samp>callout:<\/samp><var>My_Named_Credential<\/var><samp>\/<\/samp><var>some_path<\/var><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ContinuationController {\n    \/\/ Unique label corresponding to the continuation\n    public String requestLabel;\n    \/\/ Result of callout\n    public String result {get;set;}\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 service URL&gt;';\n   \n   \/\/ Action method\n    public Object startRequest() {\n      \/\/ Create continuation with a timeout\n      Continuation con = new Continuation(40);\n      \/\/ Set callback method\n      con.continuationMethod='processResponse';\n      \n      \/\/ Create callout request\n      HttpRequest req = new HttpRequest();\n      req.setMethod('GET');\n      req.setEndpoint(LONG_RUNNING_SERVICE_URL);\n      \n      \/\/ Add callout request to continuation\n      this.requestLabel = con.addHttpRequest(req);\n      \n      \/\/ Return the continuation\n      return con;  \n    }\n    \n    \/\/ Callback method \n    public Object processResponse() {   \n      \/\/ Get the response by using the unique label\n      HttpResponse response = Continuation.getResponse(this.requestLabel);\n      \/\/ Set the result variable that is displayed on the Visualforce page\n      this.result = response.getBody();\n      \n      \/\/ Return null to re-render the original Visualforce page\n      return null;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u5728\u5355\u4e2a\u5ef6\u7eed\u4e2d\u6700\u591a\u53ef\u4ee5\u521b\u5efa\u4e09\u4e2a\u5f02\u6b65\u6807\u6ce8\u3002\u6dfb\u52a0\u8fd9\u4e9b \u4f7f\u7528\u7c7b\u7684\u65b9\u6cd5\u5bf9\u540c\u4e00\u5ef6\u7eed\u7684\u6807\u6ce8\u8bf7\u6c42\u3002\u6807\u6ce8\u5e76\u884c\u8fd0\u884c\uff0c\u7528\u4e8e\u6b64\u5ef6\u7eed\u548c \u6682\u505c Visualforce \u8bf7\u6c42\u3002\u53ea\u6709\u5728\u5916\u90e8\u670d\u52a1\u8fd4\u56de\u6240\u6709\u6807\u6ce8\u540e\uff0c Visualforce \u8fdb\u7a0b\u5c06\u6062\u590d\u3002<samp>addHttpRequest<\/samp><samp>Continuation<\/samp><\/li>\n\n\n\n<li>\u5f02\u6b65\u6807\u6ce8\u4ec5\u901a\u8fc7 Visualforce \u9875\u9762\u53d7\u652f\u6301\u3002\u5236\u4f5c\u4e00\u4e2a \u901a\u8fc7\u5728 Visualforce \u9875\u9762\u5916\u90e8\u8c03\u7528\u64cd\u4f5c\u65b9\u6cd5\u8fdb\u884c\u5f02\u6b65\u6807\u6ce8\uff0c\u4f8b\u5982 \u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u4e2d\uff0c\u4e0d\u53d7\u652f\u6301\u3002<\/li>\n\n\n\n<li>\u5f02\u6b65\u6807\u6ce8\u53ef\u7528\u4e8e\u4fdd\u5b58\u7684 Apex \u63a7\u5236\u5668\u548c Visualforce \u9875\u9762 \u5728\u7248\u672c 30.0 \u53ca\u66f4\u9ad8\u7248\u672c\u4e2d\u3002\u5982\u679c\u4f7f\u7528 JavaScript \u8fdc\u7a0b\u5904\u7406\uff0c\u5219\u7248\u672c 31.0 \u6216\u66f4\u9ad8\u7248\u672c\u662f \u5fc5\u586b\u3002<\/li>\n\n\n\n<li>\u4e13\u7528\u8fde\u63a5\u4e0d\u652f\u6301\u5f02\u6b65\u6807\u6ce8\u3002<\/li>\n<\/ul>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u4f7f\u7528\u5f02\u6b65\u6807\u6ce8\u7684\u8fc7\u7a0b<br>\u82e5\u8981\u4f7f\u7528<strong>\u5f02\u6b65\u6807\u6ce8<\/strong>\uff0c\u8bf7\u5728\u63a7\u5236\u5668\u7684\u64cd\u4f5c\u65b9\u6cd5\u4e2d\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5e76\u5b9e\u73b0\u56de\u8c03\u65b9\u6cd5\u3002<samp>Continuation<\/samp><\/li>\n\n\n\n<li>\u6d4b\u8bd5<strong>\u5f02\u6b65\u6807\u6ce8<\/strong><br>\u7f16\u5199\u6d4b\u8bd5\u4ee5\u6d4b\u8bd5\u63a7\u5236\u5668\u5e76\u6ee1\u8db3\u90e8\u7f72\u6216\u6253\u5305 Apex \u7684\u4ee3\u7801\u8986\u76d6\u7387\u8981\u6c42\u3002\u7531\u4e8e Apex \u6d4b\u8bd5\u4e0d\u652f\u6301\u8fdb\u884c\u6807\u6ce8\uff0c\u56e0\u6b64\u60a8\u53ef\u4ee5\u6a21\u62df\u6807\u6ce8\u8bf7\u6c42\u548c\u54cd\u5e94\u3002\u6a21\u62df\u6807\u6ce8\u65f6\uff0c\u8bf7\u6c42\u4e0d\u4f1a\u53d1\u9001\u5230\u5916\u90e8\u670d\u52a1\uff0c\u800c\u662f\u4f7f\u7528\u6a21\u62df\u54cd\u5e94\u3002<\/li>\n\n\n\n<li><strong>\u5f02\u6b65\u6807\u6ce8\u9650\u5236<\/strong><br>\u6267\u884c\u5ef6\u7eed\u65f6\uff0c\u5c06\u5e94\u7528\u7279\u5b9a\u4e8e\u5ef6\u7eed\u7684\u9650\u5236\u3002\u5f53\u5ef6\u7eed\u8fd4\u56de\u5e76\u4e14\u8bf7\u6c42\u6062\u590d\u65f6\uff0c\u5c06\u542f\u52a8\u65b0\u7684 Apex \u4e8b\u52a1\u3002\u6240\u6709 Apex \u548c Visualforce \u9650\u5236\u5747\u9002\u7528\uff0c\u5e76\u5728\u65b0\u4e8b\u52a1\u4e2d\u91cd\u7f6e\uff0c\u5305\u62ec Apex \u6807\u6ce8\u9650\u5236\u3002<\/li>\n\n\n\n<li><strong>\u521b\u5efa\u591a\u4e2a\u5f02\u6b65\u6807\u6ce8<\/strong><br>\u8981\u4ece Visualforce \u9875\u9762\u540c\u65f6\u5bf9\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u670d\u52a1\u8fdb\u884c\u591a\u4e2a\u6807\u6ce8\uff0c\u60a8\u6700\u591a\u53ef\u4ee5\u5411 Continuation \u5b9e\u4f8b\u6dfb\u52a0\u4e09\u4e2a\u8bf7\u6c42\u3002\u4f8b\u5982\uff0c\u5f53\u60a8\u5411\u670d\u52a1\u53d1\u51fa\u72ec\u7acb\u8bf7\u6c42\u65f6\uff0c\u4f8b\u5982\u83b7\u53d6\u4e24\u79cd\u4ea7\u54c1\u7684\u5e93\u5b58\u7edf\u8ba1\u4fe1\u606f\uff0c\u4f55\u65f6\u540c\u65f6\u8fdb\u884c\u5ba3\u4f20\u3002<\/li>\n\n\n\n<li>\u94fe\u63a5\u5f02\u6b65\u6807\u6ce8<br>\u5982\u679c\u6807\u6ce8\u7684\u987a\u5e8f\u5f88\u91cd\u8981\uff0c\u6216\u8005\u5f53\u4e00\u4e2a\u6807\u6ce8\u4ee5\u53e6\u4e00\u4e2a\u6807\u6ce8\u7684\u54cd\u5e94\u4e3a\u6761\u4ef6\u65f6\uff0c\u5219\u53ef\u4ee5<strong>\u94fe\u63a5\u6807\u6ce8<\/strong>\u8bf7\u6c42\u3002\u94fe\u63a5\u6807\u6ce8\u610f\u5473\u7740\u53ea\u6709\u5728\u524d\u4e00\u4e2a\u6807\u6ce8\u7684\u54cd\u5e94\u8fd4\u56de\u540e\u624d\u4f1a\u8fdb\u884c\u4e0b\u4e00\u4e2a\u6807\u6ce8\u3002\u4f8b\u5982\uff0c\u60a8\u53ef\u80fd\u9700\u8981\u5728\u4fdd\u4fee\u670d\u52a1\u54cd\u5e94\u6307\u793a\u4fdd\u4fee\u8fc7\u671f\u540e\u94fe\u63a5\u6807\u6ce8\u4ee5\u83b7\u53d6\u4fdd\u4fee\u5ef6\u671f\u4fe1\u606f\u3002\u60a8\u6700\u591a\u53ef\u4ee5\u94fe\u63a5\u4e09\u4e2a\u6807\u6ce8\u3002<\/li>\n\n\n\n<li><strong>\u4ece\u5bfc\u5165\u7684 WSDL<\/strong><br>\u521b\u5efa\u5f02\u6b65\u6807\u6ce8 \u9664\u4e86\u57fa\u4e8e \u7684\u6807\u6ce8\u4e4b\u5916\uff0c\u4ece WSDL \u751f\u6210\u7684\u7c7b\u8fdb\u884c\u7684 Web \u670d\u52a1\u8c03\u7528\u4e2d\u8fd8\u652f\u6301\u5f02\u6b65\u6807\u6ce8\u3002\u4ece WSDL \u751f\u6210\u7684\u7c7b\u521b\u5efa\u5f02\u6b65\u6807\u6ce8\u7684\u8fc7\u7a0b\u4e0e\u4f7f\u7528\u8be5\u7c7b\u7684\u8fc7\u7a0b\u7c7b\u4f3c\u3002<samp>HttpRequestHttpRequest<\/samp><\/li>\n<\/ul>\n\n\n\n<h1 class=\"wp-block-heading\">\u4f7f\u7528\u5f02\u6b65\u6807\u6ce8\u7684\u8fc7\u7a0b<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u4f7f\u7528\u5f02\u6b65\u6807\u6ce8\uff0c\u8bf7\u5728\u63a7\u5236\u5668\u7684\u64cd\u4f5c\u65b9\u6cd5\u4e2d\u521b\u5efa\u4e00\u4e2a\u5bf9\u8c61\uff0c\u5e76\u5b9e\u73b0\u56de\u8c03 \u65b9\u6cd5\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><samp>Continuation<\/samp><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5728\u64cd\u4f5c\u65b9\u6cd5\u4e2d\u8c03\u7528\u5f02\u6b65\u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u8c03\u7528\u5f02\u6b65\u6807\u6ce8\uff0c\u8bf7\u4f7f\u7528 Visualforce \u64cd\u4f5c\u65b9\u6cd5\u4e2d\u7684\u5b9e\u4f8b\u8c03\u7528\u5916\u90e8\u670d\u52a1\u3002 \u521b\u5efa\u5ef6\u7eed\u65f6\uff0c\u53ef\u4ee5\u6307\u5b9a\u8d85\u65f6\u503c\u548c\u56de\u8c03\u7684\u540d\u79f0 \u65b9\u6cd5\u3002\u4f8b\u5982\uff0c\u4ee5\u4e0b\u4ee3\u7801\u5c06\u521b\u5efa\u4e00\u4e2a\u5177\u6709 60 \u79d2\u8d85\u65f6\u548c&nbsp;processResponse&nbsp;\u7684\u56de\u8c03\u65b9\u6cd5\u540d\u79f0\u3002<samp>Continuation<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Continuation cont = new Continuation(60);\ncont.continuationMethod = 'processResponse';<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a5\u4e0b\u6765\uff0c\u5c06\u5bf9\u8c61\u5173\u8054\u5230 \u5916\u90e8\u6807\u6ce8\u3002\u4e3a\u6b64\uff0c\u8bf7\u521b\u5efa HTTP \u8bf7\u6c42\uff0c\u7136\u540e\u5c06\u6b64\u8bf7\u6c42\u6dfb\u52a0\u5230 \u5ef6\u7eed\u5982\u4e0b\uff1a<samp>Continuation<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>String requestLabel = cont.addHttpRequest(request);<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u8fc7\u7a0b\u57fa\u4e8e\u4f7f\u7528 HttpRequest \u7c7b\u8fdb\u884c\u6807\u6ce8\u3002\u4e3e\u4e2a\u4f8b\u5b50 \u4f7f\u7528\u57fa\u4e8e WSDL \u7684\u7c7b\uff0c\u8bf7\u53c2\u9605\u4ece\u5bfc\u5165\u7684 WSDL \u521b\u5efa\u5f02\u6b65\u6807\u6ce8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8c03\u7528\u6807\u6ce8\u7684\u65b9\u6cd5\uff08\u64cd\u4f5c\u65b9\u6cd5\uff09\u5fc5\u987b\u8fd4\u56de\u5bf9\u8c61\uff0c\u4ee5\u6307\u793a Visualforce \u6302\u8d77 \u7cfb\u7edf\u53d1\u9001\u6807\u6ce8\u5e76\u7b49\u5f85\u6807\u6ce8\u54cd\u5e94\u540e\u7684\u5f53\u524d\u8bf7\u6c42\u3002\u8be5\u5bf9\u8c61\u5305\u542b \u8981\u6267\u884c\u7684\u6807\u6ce8\u3002<samp>Continuation<\/samp><samp>Continuation<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u8fd9\u662f\u8c03\u7528\u6807\u6ce8\u7684\u65b9\u6cd5\u7684\u7b7e\u540d\u3002Object \u8fd4\u56de\u7c7b\u578b \u8868\u793a .<samp>Continuation<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public Object <em>calloutActionMethodName<\/em>()<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9a\u4e49\u56de\u8c03\u65b9\u6cd5<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u5916\u90e8\u670d\u52a1\u5b8c\u6210\u6807\u6ce8\u5904\u7406\u540e\uff0c\u5c06\u8fd4\u56de\u54cd\u5e94\u3002\u4f60 \u53ef\u4ee5\u6307\u5b9a callout \u8fd4\u56de\u540e\u5f02\u6b65\u6267\u884c\u7684\u56de\u8c03\u65b9\u6cd5\u3002\u8fd9 \u56de\u8c03\u65b9\u6cd5\u5fc5\u987b\u5728 Controller \u7c7b\u4e2d\u5b9a\u4e49\uff0c\u5176\u4e2d callout \u8c03\u7528\u65b9\u6cd5 \u662f\u5b9a\u4e49\u7684\u3002\u60a8\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u56de\u8c03\u65b9\u6cd5\u6765\u5904\u7406\u8fd4\u56de\u7684\u54cd\u5e94\uff0c\u4f8b\u5982 \u68c0\u7d22\u54cd\u5e94\u4ee5\u663e\u793a\u5728 Visualforce \u9875\u9762\u4e0a\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u56de\u8c03\u65b9\u6cd5\u4e0d\u63a5\u53d7\u4efb\u4f55\u53c2\u6570\uff0c\u5e76\u5177\u6709\u6b64\u7b7e\u540d\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public Object <em>callbackMethodName<\/em>()<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Object \u8fd4\u56de\u7c7b\u578b\u8868\u793a \u3001 \u6216 \u3002\u6e32\u67d3\u539f\u59cb Visualforce \u9875\u9762\u5e76\u5b8c\u6210 Visualforce request\uff0c\u5728\u56de\u8c03\u65b9\u6cd5\u4e2d\u8fd4\u56de\u3002<samp>Continuation<\/samp><samp>PageReference<\/samp><samp>null<\/samp><samp>null<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u64cd\u4f5c\u65b9\u6cd5\u4f7f\u7528 JavaScript \u8fdc\u7a0b\u5904\u7406\uff08\u5e26\u6709 \u6ce8\u91ca\uff09\uff0c\u5219\u56de\u8c03\u65b9\u6cd5\u5fc5\u987b\u662f\u9759\u6001\u7684\uff0c\u5e76\u4e14\u5177\u6709 \u652f\u6301\u4ee5\u4e0b\u7b7e\u540d\u3002<samp>@RemoteAction<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static Object <em>callbackMethodName<\/em>(List&lt; String&gt; <em>labels<\/em>, Object <em>state<\/em>)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u827a\u672f<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public static Object <em>callbackMethodName<\/em>(Object <em>state<\/em>)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u8be5\u53c2\u6570\u7531\u7cfb\u7edf\u5728\u8c03\u7528 callback \u65b9\u6cd5\uff0c\u5e76\u4fdd\u5b58\u4e0e\u53d1\u51fa\u7684\u6807\u6ce8\u8bf7\u6c42\u5173\u8054\u7684\u6807\u7b7e\u3002\u8be5\u53c2\u6570\u662f\u901a\u8fc7\u5728\u63a7\u5236\u5668\u4e2d\u8bbe\u7f6e\u00a0Continuation.state\u00a0\u5c5e\u6027\u6765\u63d0\u4f9b\u7684\u3002<var>labelsstate<\/var><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u8868\u5217\u51fa\u4e86\u56de\u8c03\u65b9\u6cd5\u7684\u8fd4\u56de\u503c\u3002\u6bcf\u4e2a\u8fd4\u56de\u503c\u5bf9\u5e94 \u5230\u4e0d\u540c\u7684\u884c\u4e3a\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Callback \u65b9\u6cd5\u8fd4\u56de\u503c<\/th><th>\u8bf7\u6c42\u751f\u547d\u5468\u671f\u548c\u7ed3\u679c<\/th><\/tr><\/thead><tbody><tr><td><samp>null<\/samp><\/td><td>\u7cfb\u7edf\u5b8c\u6210 Visualforce \u9875\u9762\u8bf7\u6c42\u5e76\u5448\u73b0\u539f\u59cb Visualforce \u9875\u9762\uff08\u6216\u5176\u4e2d\u7684\u4e00\u90e8\u5206\uff09\u3002<\/td><\/tr><tr><td><samp>PageReference<\/samp><\/td><td>\u7cfb\u7edf\u5b8c\u6210 Visualforce \u9875\u9762\u8bf7\u6c42\u5e76\u91cd\u5b9a\u5411\u5230\u65b0\u7684 Visualforce \u9875\u9762\u3002\uff08\u4f7f\u7528 \u4e2d\u7684\u67e5\u8be2\u53c2\u6570\u5c06 \u7684\u7ed3\u679c\u4f20\u9012\u5230\u65b0\u9875\u9762\u3002<samp>PageReference<\/samp><samp>Continuation<\/samp><\/td><\/tr><tr><td><samp>Continuation<\/samp><\/td><td>\u7cfb\u7edf\u518d\u6b21\u6682\u505c Visualforce \u8bf7\u6c42\uff0c\u5e76\u7b49\u5f85 \u65b0\u7684\u6807\u6ce8\u3002\u8fd4\u56de\u65b0\u7684 \u7528\u4e8e\u94fe\u63a5\u5f02\u6b65\u6807\u6ce8\u7684\u56de\u8c03\u65b9\u6cd5\u3002<samp>Continuation<\/samp><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u672a\u4e3a\u5ef6\u7eed\u8bbe\u7f6e\u5c5e\u6027\uff0c\u5219\u4f7f\u7528\u76f8\u540c\u7684\u64cd\u4f5c\u65b9\u6cd5 \u8fd9\u4f7f\u5f97\u6807\u6ce8\u5728\u6807\u6ce8\u54cd\u5e94\u8fd4\u56de\u65f6\u518d\u6b21\u8c03\u7528\u3002<samp>continuationMethod<\/samp><\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u6d4b\u8bd5\u5f02\u6b65\u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u7f16\u5199\u6d4b\u8bd5\u4ee5\u6d4b\u8bd5\u63a7\u5236\u5668\u5e76\u6ee1\u8db3\u90e8\u7f72\u7684\u4ee3\u7801\u8986\u76d6\u7387\u8981\u6c42 \u6216\u5305\u88c5 Apex\u3002\u7531\u4e8e Apex \u6d4b\u8bd5\u4e0d\u652f\u6301\u8fdb\u884c\u6807\u6ce8\uff0c\u56e0\u6b64\u60a8\u53ef\u4ee5\u6a21\u62df \u6807\u6ce8\u8bf7\u6c42\u548c\u54cd\u5e94\u3002\u6a21\u62df\u6807\u6ce8\u65f6\uff0c\u8bf7\u6c42\u4e0d\u4f1a\u5f97\u5230 \u53d1\u9001\u5230\u5916\u90e8\u670d\u52a1\uff0c\u5e76\u4f7f\u7528\u6a21\u62df\u54cd\u5e94\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4e0b\u9762\u7684\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u5728 Web \u6d4b\u8bd5\u4e2d\u8c03\u7528\u6a21\u62df\u5f02\u6b65\u6807\u6ce8 \u4f7f\u7528 \u7684\u670d\u52a1\u8c03\u7528\u3002\u6a21\u62df \u6807\u6ce8\uff0c\u8c03\u7528\u7c7b\u7684\u4ee5\u4e0b\u65b9\u6cd5\uff1aTest.setContinuationResponse\uff08\uff09 \u548c Test.invokeContinuationMethod\uff08\uff09\u3002<samp>HTTPRequestTest<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u9996\u5148\u5217\u51fa\u8981\u6d4b\u8bd5\u7684\u63a7\u5236\u5668\u7c7b\uff0c\u7136\u540e\u662f\u6d4b\u8bd5\u7c7b\u3002\u63a7\u5236\u5668 \u6b64\u5904\u91cd\u7528\u4e86 Make Long-Running Callouts with Continuations\u00a0\u4e2d\u7684\u7c7b\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ContinuationController {\n    \/\/ Unique label corresponding to the continuation request\n    public String requestLabel;\n    \/\/ Result of callout\n    public String result {get;set;}\n    \/\/ Endpoint of long-running service\n    private static final String LONG_RUNNING_SERVICE_URL = \n        '&lt;Insert your service URL&gt;';\n   \n   \/\/ Action method\n    public Object startRequest() {\n      \/\/ Create continuation with a timeout\n      Continuation con = new Continuation(40);\n      \/\/ Set callback method\n      con.continuationMethod='processResponse';\n      \n      \/\/ Create callout request\n      HttpRequest req = new HttpRequest();\n      req.setMethod('GET');\n      req.setEndpoint(LONG_RUNNING_SERVICE_URL);\n      \n      \/\/ Add callout request to continuation\n      this.requestLabel = con.addHttpRequest(req);\n      \n      \/\/ Return the continuation\n      return con;  \n    }\n    \n    \/\/ Callback method \n    public Object processResponse() {   \n      \/\/ Get the response by using the unique label\n      HttpResponse response = Continuation.getResponse(this.requestLabel);\n      \/\/ Set the result variable that is displayed on the Visualforce page\n      this.result = response.getBody();\n      \n      \/\/ Return null to re-render the original Visualforce page\n      return null;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u663e\u793a\u4e0e\u63a7\u5236\u5668\u5bf9\u5e94\u7684\u6d4b\u8bd5\u7c7b\u3002\u6b64\u6d4b\u8bd5\u7c7b \u5305\u542b\u7528\u4e8e\u6d4b\u8bd5\u5f02\u6b65\u6807\u6ce8\u7684\u6d4b\u8bd5\u65b9\u6cd5\u3002\u5728\u6d4b\u8bd5\u65b9\u6cd5\u4e2d\uff0c\u8bbe\u7f6e\u4e00\u4e2a\u6a21\u62df\u54cd\u5e94\uff0c \u5e76\u5bfc\u81f4 callback \u65b9\u6cd5\u3002\u8be5\u6d4b\u8bd5\u786e\u4fdd\u56de\u8c03 \u65b9\u6cd5\u901a\u8fc7\u9a8c\u8bc1\u63a7\u5236\u5668\u7684\u7ed3\u679c\u53d8\u91cf \u8bbe\u7f6e\u4e3a\u9884\u671f\u7684\u54cd\u5e94\u3002<samp>Test.setContinuationResponse<\/samp><samp>Test.invokeContinuationMethod<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\npublic class ContinuationTestingForHttpRequest {\n    public static testmethod void testWebService() {\n        ContinuationController controller = new ContinuationController();\n        \/\/ Invoke the continuation by calling the action method\n        Continuation conti = (Continuation)controller.startRequest();\n        \n        \/\/ Verify that the continuation has the proper requests\n        Map&lt;String, HttpRequest&gt; requests = conti.getRequests();\n        system.assert(requests.size() == 1);\n        system.assert(requests.get(controller.requestLabel) != null);\n        \n        \/\/ Perform mock callout \n        \/\/ (i.e. skip the callout and call the callback method)\n        HttpResponse response = new HttpResponse();\n        response.setBody('Mock response body');   \n        \/\/ Set the fake response for the continuation     \n        Test.setContinuationResponse(controller.requestLabel, response);\n        \/\/ Invoke callback method\n        Object result = Test.invokeContinuationMethod(controller, conti);\n        \/\/ result is the return value of the callback\n        System.assertEquals(null, result);\n        \/\/ Verify that the controller's result variable\n        \/\/   is set to the mock response.\n        System.assertEquals('Mock response body', controller.result);\n    }\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u5f02\u6b65\u6807\u6ce8\u9650\u5236<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u6267\u884c\u5ef6\u7eed\u65f6\uff0c\u5c06\u9002\u7528\u7279\u5b9a\u4e8e\u5ef6\u7eed\u7684\u9650\u5236\u3002\u5f53 \u5ef6\u7eed\u8fd4\u56de\uff0c\u8bf7\u6c42\u6062\u590d\uff0c\u65b0\u7684 Apex \u4e8b\u52a1\u5f00\u59cb\u3002\u6240\u6709 Apex \u548c Visualforce \u9650\u5236\u9002\u7528\uff0c\u5e76\u5728\u65b0\u4e8b\u52a1\u4e2d\u91cd\u7f6e\uff0c\u5305\u62ec Apex \u6807\u6ce8 \u9650\u5236\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5ef6\u7eed\u7279\u5b9a\u9650\u5236<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u7279\u5b9a\u4e8e\u5ef6\u7eed\u7684 Apex \u548c Visualforce \u9650\u5236\u3002<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>\u63cf\u8ff0<\/th><th>\u9650\u5236<\/th><\/tr><\/thead><tbody><tr><td>\u5355\u4e2a\u5ef6\u7eed\u4e2d\u5e76\u884c Apex \u6807\u6ce8\u7684\u6700\u5927\u6570\u91cf<\/td><td>3<\/td><\/tr><tr><td>\u94fe\u5f0f Apex \u6807\u6ce8\u7684\u6700\u5927\u6570\u91cf<\/td><td>3<\/td><\/tr><tr><td>\u5355\u4e2a\u5ef6\u7eed\u7684\u6700\u5927\u8d85\u65f6<sup>1<\/sup><\/td><td><a><\/a>120 \u79d2<\/td><\/tr><tr><td>\u6700\u5927 Visualforce \u63a7\u5236\u5668\u72b6\u6001\u5927\u5c0f<sup>2<\/sup><\/td><td>80 KB<\/td><\/tr><tr><td>\u6700\u5927 HTTP \u54cd\u5e94\u5927\u5c0f<\/td><td>1 \u5146\u5b57\u8282<\/td><\/tr><tr><td>\u6700\u5927 HTTP POST \u8868\u5355\u5927\u5c0f &#8211; \u6240\u6709\u952e\u548c\u503c\u7684\u5927\u5c0f \u5f62\u5f0f<sup>3<\/sup><\/td><td>1 \u5146\u5b57\u8282<\/td><\/tr><tr><td>HTTP POST \u8868\u5355\u4e2d\u7684\u6700\u5927\u5bc6\u94a5\u6570<sup>3<\/sup><\/td><td>500<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\"><sup>1<\/sup>\u5728\u81ea\u52a8\u751f\u6210\u7684 Web \u670d\u52a1\u5b58\u6839\u548c HttpRequest \u5bf9\u8c61\u5c06\u88ab\u5ffd\u7565\u3002\u5bf9\u4e8e\u5ef6\u7eed\uff0c\u4ec5\u5f3a\u5236\u6267\u884c\u6b64\u8d85\u65f6\u9650\u5236\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><sup>2<\/sup>\u6267\u884c\u5ef6\u7eed\u65f6\uff0c\u5c06\u5bf9 Visualforce \u63a7\u5236\u5668\u8fdb\u884c\u5e8f\u5217\u5316\u3002 \u5ef6\u7eed\u5b8c\u6210\u540e\uff0c\u63a7\u5236\u5668\u88ab\u53cd\u5e8f\u5217\u5316\uff0c\u56de\u8c03 \u8c03\u7528\u3002\u4f7f\u7528 Apex \u4fee\u9970\u7b26\u53ef\u4ee5 \u6307\u5b9a\u4e0d\u5e8f\u5217\u5316\u7684\u53d8\u91cf\u3002\u8be5\u6846\u67b6\u4ec5\u4f7f\u7528\u5e8f\u5217\u5316 \u6210\u5458\uff0c\u5f53\u5b83\u6062\u590d\u65f6\u3002\u63a7\u5236\u5668\u72b6\u6001\u5927\u5c0f\u9650\u5236\u4e0e\u89c6\u56fe\u72b6\u6001\u662f\u5206\u5f00\u7684 \u9650\u5236\u3002\u8bf7\u53c2\u89c1\u5ef6\u7eed\u63a7\u5236\u5668\u72b6\u6001\u548c Visualforce \u89c6\u56fe\u72b6\u6001\u3002<samp>transient<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><sup>3<\/sup>\u6b64\u9650\u5236\u9002\u7528\u4e8e\u5177\u6709\u4ee5\u4e0b\u5185\u5bb9\u7c7b\u578b\u6807\u5934\u7684HTTP POST\u8868\u5355\uff1acontent-type=&#8217;application\/x-www-form-urlencoded&#8217;\u548ccontent-type=&#8217;multipart\/form-data&#8217;<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><a><\/a>\u5ef6\u7eed\u63a7\u5236\u5668\u72b6\u6001\u548c Visualforce \u89c6\u56fe\u72b6\u6001<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u63a7\u5236\u5668\u72b6\u6001\u548c\u89c6\u56fe\u72b6\u6001\u662f\u4e0d\u540c\u7684\u3002\u5ef6\u7eed\u7684\u63a7\u5236\u5668\u72b6\u6001\u5305\u62ec \u8bf7\u6c42\u4e2d\u6d89\u53ca\u7684\u6240\u6709\u63a7\u5236\u5668\u7684\u5e8f\u5217\u5316\uff0c\u800c\u4e0d\u4ec5\u4ec5\u662f \u8c03\u7528\u5ef6\u7eed\u7684\u63a7\u5236\u5668\u3002\u5e8f\u5217\u5316\u63a7\u5236\u5668\u5305\u62ec\u63a7\u5236\u5668 \u6269\u5c55\uff0c\u4ee5\u53ca\u81ea\u5b9a\u4e49\u548c\u5185\u90e8\u7ec4\u4ef6\u63a7\u5236\u5668\u3002\u63a7\u5236\u5668\u72b6\u6001\u5927\u5c0f\u4e3a \u4f5c\u4e3a\u4e8b\u4ef6\u8bb0\u5f55\u5728\u8c03\u8bd5\u65e5\u5fd7\u4e2d\u3002<samp>USER_DEBUG<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u89c6\u56fe\u72b6\u6001\u6bd4\u63a7\u5236\u5668\u72b6\u6001\u4fdd\u5b58\u7684\u6570\u636e\u66f4\u591a\uff0c\u5e76\u4e14\u5177\u6709\u66f4\u9ad8\u7684\u6700\u5927\u5927\u5c0f \uff08170KB\uff09\u3002 \u89c6\u56fe\u72b6\u6001\u5305\u542b\u72b6\u6001\u548c\u7ec4\u4ef6\u7ed3\u6784\u3002\u72b6\u6001\u662f\u6240\u6709 \u63a7\u5236\u5668\u548c\u9875\u9762\u4e0a\u6bcf\u4e2a\u7ec4\u4ef6\u7684\u6240\u6709\u5c5e\u6027\uff0c\u5305\u62ec\u5b50\u9875\u9762\u548c \u5b50\u7ec4\u4ef6\u3002\u7ec4\u4ef6\u7ed3\u6784\u662f\u7ec4\u4ef6\u7684\u7236\u5b50\u5173\u7cfb \u5728\u9875\u9762\u4e2d\u3002\u60a8\u53ef\u4ee5\u5728\u5f00\u53d1\u8005\u63a7\u5236\u53f0\u6216\u9875\u811a\u4e2d\u76d1\u63a7\u89c6\u56fe\u72b6\u6001\u5927\u5c0f \u542f\u7528\u5f00\u53d1\u6a21\u5f0f\u65f6\u7684 Visualforce \u9875\u9762\u3002\u6709\u5173\u8be6\u7ec6\u4fe1\u606f\uff0c\u8bf7\u53c2\u9605\u201c\u67e5\u770b \u72b6\u6001\u9009\u9879\u5361\u201c\uff0c\u6216\u53c2\u8003\u00a0Visualforce \u5f00\u53d1\u4eba\u5458\u7684 \u6307\u5357\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u8fdb\u884c\u591a\u4e2a\u5f02\u6b65\u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ece Visualforce \u540c\u65f6\u5bf9\u957f\u65f6\u95f4\u8fd0\u884c\u7684\u670d\u52a1\u8fdb\u884c\u591a\u4e2a\u6807\u6ce8 \u9875\u9762\u4e0a\uff0c\u60a8\u6700\u591a\u53ef\u4ee5\u5411 Continuation \u5b9e\u4f8b\u6dfb\u52a0\u4e09\u4e2a\u8bf7\u6c42\u3002\u4f55\u65f6 \u201c\u540c\u65f6\u6807\u6ce8\u201d\u662f\u6307\u5411\u670d\u52a1\u53d1\u51fa\u72ec\u7acb\u8bf7\u6c42\uff0c\u4f8b\u5982 \u83b7\u53d6\u4e24\u79cd\u4ea7\u54c1\u7684\u5e93\u5b58\u7edf\u8ba1\u4fe1\u606f\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u60a8\u5728\u540c\u4e00\u5ef6\u7eed\u4e2d\u5236\u4f5c\u591a\u4e2a\u6807\u6ce8\u65f6\uff0c\u6807\u6ce8\u8bf7\u6c42\u4f1a\u8fd0\u884c \u5e76\u884c\u5e76\u6302\u8d77 Visualforce \u8bf7\u6c42\u3002\u4ec5\u5728\u8fd4\u56de\u6240\u6709\u6807\u6ce8\u54cd\u5e94\u540e Visualforce \u8fdb\u7a0b\u662f\u5426\u6062\u590d\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b Visualforce \u548c Apex \u793a\u4f8b\u663e\u793a\u4e86\u5982\u4f55\u8fdb\u884c\u4e24\u4e2a\u5f02\u6b65\u6807\u6ce8 \u540c\u65f6\u4f7f\u7528\u5355\u4e2a\u5ef6\u7eed\u3002\u9996\u5148\u663e\u793a Visualforce \u9875\u9762\u3002\u8fd9 Visualforce \u9875\u9762\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u7528\u4e8e\u8c03\u7528\u63a7\u5236\u5668\u4e2d\u7684\u64cd\u4f5c\u65b9\u6cd5\u3002\u5f53 Visualforce \u8fdb\u7a0b\u6062\u590d\uff0coutputPanel&nbsp;\u7ec4\u4ef6\u88ab\u6e32\u67d3 \u518d\u3002\u6b64\u9762\u677f\u663e\u793a\u4e24\u4e2a\u5f02\u6b65\u6807\u6ce8\u7684\u54cd\u5e94\u3002<samp>startRequestsInParallel<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;apex:page controller=\"MultipleCalloutController\" showChat=\"false\" showHeader=\"false\"&gt;\n   &lt;apex:form &gt;\n      &lt;!-- Invokes the action method when the user clicks this button. --&gt;\n      &lt;apex:commandButton action=\"{!startRequestsInParallel}\" value=\"Start Request\" reRender=\"panel\"\/&gt;  \n   &lt;\/apex:form&gt;\n\n   &lt;apex:outputPanel id=\"panel\"&gt;\n       &lt;!-- Displays the response body of the initial callout. --&gt;   \n       &lt;apex:outputText value=\"{!result1}\" \/&gt;\n       \n       &lt;br\/&gt;\n       &lt;!-- Displays the response body of the chained callout. --&gt;\n       &lt;apex:outputText value=\"{!result2}\" \/&gt;\n   &lt;\/apex:outputPanel&gt; \n   \n&lt;\/apex:page&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u663e\u793a Visualforce \u9875\u9762\u7684\u63a7\u5236\u5668\u7c7b\u3002\u8be5\u65b9\u6cd5\u5c06\u4e24\u4e2a\u8bf7\u6c42\u6dfb\u52a0\u5230 \u5ef6\u7eed\u3002\u8fd4\u56de\u6240\u6709\u6807\u6ce8\u54cd\u5e94\u540e\uff0c\u5c06\u8c03\u7528\u56de\u8c03\u65b9\u6cd5 \uff08\uff09 \u5e76\u5904\u7406 \u53cd\u5e94\u3002<samp>startRequestsInParallel<\/samp><samp>processAllResponses<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class MultipleCalloutController {\n\n    \/\/ Unique label for the first request\n    public String requestLabel1;\n    \/\/ Unique label for the second request\n    public String requestLabel2;\n    \/\/ Result of first callout\n    public String result1 {get;set;}\n   \/\/ Result of second callout\n    public String result2 {get;set;}\n    \/\/ Endpoints of long-running service\n    private static final String LONG_RUNNING_SERVICE_URL1 = \n        '&lt;Insert your first service URL&gt;';\n    private static final String LONG_RUNNING_SERVICE_URL2 = \n        '&lt;Insert your second service URL&gt;';\n           \n    \/\/ Action method\n    public Object startRequestsInParallel() {\n      \/\/ Create continuation with a timeout\n      Continuation con = new Continuation(60);\n      \/\/ Set callback method\n      con.continuationMethod='processAllResponses';\n      \n      \/\/ Create first callout request\n      HttpRequest req1 = new HttpRequest();\n      req1.setMethod('GET');\n      req1.setEndpoint(LONG_RUNNING_SERVICE_URL1);\n      \n      \/\/ Add first callout request to continuation\n      this.requestLabel1 = con.addHttpRequest(req1);     \n      \n      \/\/ Create second callout request\n      HttpRequest req2 = new HttpRequest();\n      req2.setMethod('GET');\n      req2.setEndpoint(LONG_RUNNING_SERVICE_URL2);\n      \n      \/\/ Add second callout request to continuation\n      this.requestLabel2 = con.addHttpRequest(req2);     \n      \n      \/\/ Return the continuation\n      return con;  \n    }\n    \n    \/\/ Callback method.\n    \/\/ Invoked only when responses of all callouts are returned.\n    public Object processAllResponses() {   \n      \/\/ Get the response of the first request\n      HttpResponse response1 = Continuation.getResponse(this.requestLabel1);\n      this.result1 = response1.getBody();\n\n      \/\/ Get the response of the second request\n      HttpResponse response2 = Continuation.getResponse(this.requestLabel2);\n      this.result2 = response2.getBody();\n                 \n      \/\/ Return null to re-render the original Visualforce page\n      return null;\n    }\n}<\/code><\/pre>\n\n\n\n<h1 class=\"wp-block-heading\">\u94fe\u63a5\u5f02\u6b65\u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u5982\u679c\u6807\u6ce8\u7684\u987a\u5e8f\u5f88\u91cd\u8981\uff0c\u6216\u8005\u6807\u6ce8\u4ee5\u54cd\u5e94\u4e3a\u6761\u4ef6 \u5728\u53e6\u4e00\u4e2a\u6807\u6ce8\u4e2d\uff0c\u60a8\u53ef\u4ee5\u94fe\u63a5\u6807\u6ce8\u8bf7\u6c42\u3002\u94fe\u63a5\u6807\u6ce8\u610f\u5473\u7740\u4e0b\u4e00\u4e2a \u53ea\u6709\u5728\u524d\u4e00\u4e2a\u6807\u6ce8\u7684\u54cd\u5e94\u8fd4\u56de\u540e\uff0c\u624d\u4f1a\u8fdb\u884c\u6807\u6ce8\u3002\u4f8b\u5982\uff0c\u60a8 \u53ef\u80fd\u9700\u8981\u5728\u4fdd\u4fee\u670d\u52a1\u540e\u94fe\u63a5\u6807\u6ce8\u4ee5\u83b7\u53d6\u4fdd\u4fee\u5ef6\u671f\u4fe1\u606f \u54cd\u5e94\u8868\u793a\u4fdd\u4fee\u5df2\u8fc7\u671f\u3002\u60a8\u6700\u591a\u53ef\u4ee5\u94fe\u63a5\u4e09\u4e2a\u6807\u6ce8\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b Visualforce \u548c Apex \u793a\u4f8b\u6f14\u793a\u5982\u4f55\u5c06\u4e00\u4e2a\u6807\u6ce8\u94fe\u63a5\u5230\u53e6\u4e00\u4e2a\u6807\u6ce8\u3002 \u9996\u5148\u663e\u793a Visualforce \u9875\u9762\u3002Visualforce \u9875\u9762\u5305\u542b\u4e00\u4e2a\u6309\u94ae\uff0c\u7528\u4e8e\u8c03\u7528 \u64cd\u4f5c\u65b9\u6cd5 \u63a7\u5236\u5668\u3002\u6bcf\u6b21\u8fd4\u56de\u5ef6\u7eed\u65f6\uff0cVisualforce \u8fdb\u7a0b\u90fd\u4f1a\u6682\u505c\u3002 Visualforce \u8fdb\u7a0b\u5728\u8fd4\u56de\u6bcf\u4e2a\u54cd\u5e94\u540e\u6062\u590d\uff0c\u5e76\u5448\u73b0\u6bcf\u4e2a\u54cd\u5e94&nbsp;outputPanel&nbsp;\u7ec4\u4ef6\u4e2d\u7684\u54cd\u5e94\u3002<samp>invokeInitialRequest<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;apex:page controller=\"ChainedContinuationController\" showChat=\"false\" showHeader=\"false\"&gt;\n   &lt;apex:form &gt;\n      &lt;!-- Invokes the action method when the user clicks this button. --&gt;\n      &lt;apex:commandButton action=\"{!invokeInitialRequest}\" value=\"Start Request\" reRender=\"panel\"\/&gt;  \n   &lt;\/apex:form&gt;\n\n   &lt;apex:outputPanel id=\"panel\"&gt;\n       &lt;!-- Displays the response body of the initial callout. --&gt;   \n       &lt;apex:outputText value=\"{!result1}\" \/&gt;\n       \n       &lt;br\/&gt;\n       &lt;!-- Displays the response body of the chained callout. --&gt;\n       &lt;apex:outputText value=\"{!result2}\" \/&gt;\n   &lt;\/apex:outputPanel&gt; \n   \n&lt;\/apex:page&gt;<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u663e\u793a Visualforce \u9875\u9762\u7684\u63a7\u5236\u5668\u7c7b\u3002\u8be5\u65b9\u6cd5\u521b\u5efa\u7b2c\u4e00\u4e2a \u5ef6\u7eed\u3002\u56de\u8c03\u65b9\u6cd5 \uff08\uff09 \u5904\u7406\u7b2c\u4e00\u4e2a\u6807\u6ce8\u7684\u54cd\u5e94\u3002\u5982\u679c \u6b64\u54cd\u5e94\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6\uff0c\u8be5\u65b9\u6cd5\u901a\u8fc7\u8fd4\u56de\u6765\u94fe\u63a5\u53e6\u4e00\u4e2a\u6807\u6ce8 \u7b2c\u4e8c\u4e2a\u5ef6\u7eed\u3002\u8fd4\u56de\u94fe\u5f0f\u5ef6\u7eed\u7684\u54cd\u5e94\u540e\uff0c \u7b2c\u4e8c\u4e2a\u56de\u8c03\u65b9\u6cd5 \uff08\uff09 \u88ab\u8c03\u7528\u5e76\u5904\u7406\u7b2c\u4e8c\u4e2a\u54cd\u5e94\u3002<samp>invokeInitialRequest<\/samp><samp>processInitialResponse<\/samp><samp>processChainedResponse<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public with sharing class ChainedContinuationController {\n\n    \/\/ Unique label for the initial callout request\n    public String requestLabel1;\n    \/\/ Unique label for the chained callout request\n    public String requestLabel2;\n    \/\/ Result of initial callout\n    public String result1 {get;set;}\n    \/\/ Result of chained callout\n    public String result2 {get;set;}\n    \/\/ Endpoint of long-running service\n    private static final String LONG_RUNNING_SERVICE_URL1 = \n        '&lt;Insert your first service URL&gt;';\n    private static final String LONG_RUNNING_SERVICE_URL2 = \n        '&lt;Insert your second service URL&gt;';\n           \n    \/\/ Action method\n    public Object invokeInitialRequest() {\n      \/\/ Create continuation with a timeout\n      Continuation con = new Continuation(60);\n      \/\/ Set callback method\n      con.continuationMethod='processInitialResponse';\n      \n      \/\/ Create first callout request\n      HttpRequest req = new HttpRequest();\n      req.setMethod('GET');\n      req.setEndpoint(LONG_RUNNING_SERVICE_URL1);\n      \n      \/\/ Add initial callout request to continuation\n      this.requestLabel1 = con.addHttpRequest(req);              \n      \n      \/\/ Return the continuation\n      return con;  \n    }\n    \n    \/\/ Callback method for initial request\n    public Object processInitialResponse() {   \n      \/\/ Get the response by using the unique label\n      HttpResponse response = Continuation.getResponse(this.requestLabel1);\n      \/\/ Set the result variable that is displayed on the Visualforce page\n      this.result1 = response.getBody();\n           \n      Continuation chainedContinuation = null;\n      \/\/ Chain continuation if some condition is met\n      if (response.getBody().toLowerCase().contains('expired')) {\n          \/\/ Create a second continuation \n          chainedContinuation = new Continuation(60);\n          \/\/ Set callback method\n          chainedContinuation.continuationMethod='processChainedResponse';\n          \n          \/\/ Create callout request\n          HttpRequest req = new HttpRequest();\n          req.setMethod('GET');\n          req.setEndpoint(LONG_RUNNING_SERVICE_URL2);\n          \n          \/\/ Add callout request to continuation\n          this.requestLabel2 = chainedContinuation.addHttpRequest(req); \n      }\n      \n      \/\/ Start another continuation \n      return chainedContinuation;  \n    }    \n    \n    \/\/ Callback method for chained request\n    public Object processChainedResponse() {   \n      \/\/ Get the response for the chained request\n      HttpResponse response = Continuation.getResponse(this.requestLabel2);\n      \/\/ Set the result variable that is displayed on the Visualforce page\n      this.result2 = response.getBody();\n           \n      \/\/ Return null to re-render the original Visualforce page\n      return null;\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6ce8\u610f<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728\u521b\u5efa\u65b0\u7684\u5ef6\u7eed\u4e4b\u524d\uff0c\u5fc5\u987b\u68c0\u7d22\u5ef6\u7eed\u7684\u54cd\u5e94 \u4ee5\u53ca Visualforce \u8bf7\u6c42\u518d\u6b21\u6682\u505c\u4e4b\u524d\u3002\u60a8\u65e0\u6cd5\u68c0\u7d22\u65e7\u7684 \u6765\u81ea\u5ef6\u7eed\u94fe\u4e2d\u8f83\u65e9\u5ef6\u7eed\u7684\u56de\u5e94\u3002<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">\u4ece\u5bfc\u5165\u7684 WSDL \u8fdb\u884c\u5f02\u6b65\u6807\u6ce8<\/h1>\n\n\n\n<p class=\"wp-block-paragraph\">\u9664\u4e86\u57fa\u4e8e -\u7684\u6807\u6ce8\u4e4b\u5916\uff0c \u5728\u4ece WSDL \u751f\u6210\u7684 Web \u670d\u52a1\u8c03\u7528\u4e2d\u652f\u6301\u5f02\u6b65\u6807\u6ce8 \u7c7b\u3002\u4ece WSDL \u751f\u6210\u7684\u7c7b\u8fdb\u884c\u5f02\u6b65\u6807\u6ce8\u7684\u8fc7\u7a0b\u4e0e\u6b64\u7c7b\u4f3c \u5230\u4f7f\u7528\u7c7b\u7684\u8fc7\u7a0b\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><samp>HttpRequest<\/samp><samp>HttpRequest<\/samp><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u5728 Salesforce \u4e2d\u5bfc\u5165 WSDL \u65f6\uff0cSalesforce \u4f1a\u4e3a\u6bcf\u4e2a\u7c7b\u81ea\u52a8\u751f\u6210\u4e24\u4e2a Apex \u7c7b \u547d\u540d\u7a7a\u95f4\u3002\u4e00\u4e2a\u7c7b\u662f\u540c\u6b65\u7684\u670d\u52a1\u7c7b \u670d\u52a1\uff0c\u53e6\u4e00\u4e2a\u662f\u5f02\u6b65\u670d\u52a1\u7684\u4fee\u6539\u7248\u672c\u3002\u8fd9 \u81ea\u52a8\u751f\u6210\u7684\u5f02\u6b65\u7c7b\u540d\u4ee5&nbsp;Async&nbsp;\u524d\u7f00\u5f00\u5934 \u5176\u683c\u5f0f\u4e3a&nbsp;Async<var>ServiceName<\/var>\u3002 \u662f\u539f\u59cb\u672a\u4fee\u6539\u7684\u670d\u52a1\u7c7b\u7684\u540d\u79f0\u3002 \u5f02\u6b65\u7c7b\u5728\u4ee5\u4e0b\u65b9\u9762\u4e0e\u6807\u51c6\u7c7b\u4e0d\u540c\u3002<var>ServiceName<\/var><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u516c\u5171\u670d\u52a1\u65b9\u6cd5\u5305\u542b\u4e00\u4e2a\u989d\u5916\u7684\u53c2\u6570\u4f5c\u4e3a\u7b2c\u4e00\u4e2a\u53c2\u6570\u3002<samp>Continuation<\/samp><\/li>\n\n\n\n<li>Web \u670d\u52a1\u64cd\u4f5c\u662f\u5f02\u6b65\u8c03\u7528\u7684\uff0c\u5176\u54cd\u5e94\u662f \u7528 response \u5143\u7d20\u3002<samp>getValue<\/samp><\/li>\n\n\n\n<li>\u548c \u4e60\u60ef\u4e8e \u5206\u522b\u8c03\u7528\u670d\u52a1\u548c\u83b7\u53d6\u54cd\u5e94\u3002<samp>WebServiceCallout.beginInvoke<\/samp><samp>WebServiceCallout.endInvoke<\/samp><\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">\u60a8\u53ef\u4ee5\u5728 Salesforce \u7528\u6237\u754c\u9762\u4e2d\u4ece WSDL \u751f\u6210 Apex \u7c7b\u3002\u4ece\u8bbe\u7f6e\u4e2d\uff0c \u5728\u201c\u5feb\u901f\u67e5\u627e\u201d\u6846\u4e2d\u8f93\u5165&nbsp;<strong>Apex \u7c7b<\/strong>\uff0c \u7136\u540e\u9009\u62e9&nbsp;<strong>Apex \u7c7b<\/strong>\u3002<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">\u82e5\u8981\u8fdb\u884c\u5f02\u6b65 Web \u670d\u52a1\u6807\u6ce8\uff0c\u8bf7\u5728\u81ea\u52a8\u751f\u6210\u7684 \u5f02\u6b65\u7c7b\uff0c\u65b9\u6cd5\u662f\u5c06\u5b9e\u4f8b\u4f20\u9012\u7ed9\u8fd9\u4e9b\u65b9\u6cd5\u3002\u4ee5\u4e0b\u793a\u4f8b\u57fa\u4e8e\u5047\u8bbe\u7684\u80a1\u7968\u62a5\u4ef7 \u670d\u52a1\u3002\u6b64\u793a\u4f8b\u5047\u5b9a\u7ec4\u7ec7\u5177\u6709\u4e00\u4e2a\u540d\u4e3a \u7684\u7c7b\uff0c\u8be5\u7c7b\u662f\u81ea\u52a8\u751f\u6210\u7684 \u901a\u8fc7 WSDL \u5bfc\u5165\u3002\u8be5\u793a\u4f8b\u6f14\u793a\u5982\u4f55\u5bf9\u670d\u52a1\u8fdb\u884c\u5f02\u6b65\u6807\u6ce8 \u901a\u8fc7\u4f7f\u7528\u81ea\u52a8\u751f\u6210\u7684\u7c7b\u3002\u9996\u5148\uff0c\u6b64\u793a\u4f8b\u521b\u5efa\u4e00\u4e2a \u4ee5 60 \u79d2\u7684\u8d85\u65f6\u65f6\u95f4\u7ee7\u7eed\uff0c\u5e76\u8bbe\u7f6e\u56de\u8c03\u65b9\u6cd5\u3002\u63a5\u4e0b\u6765\uff0c\u4ee3\u7801 \u793a\u4f8b\u8c03\u7528\u65b9\u6cd5 \u5c06 Continuation \u5b9e\u4f8b\u4f20\u9012\u7ed9\u5b83\u3002\u65b9\u6cd5\u8c03\u7528\u5bf9\u5e94\u4e8e\u5f02\u6b65\u6807\u6ce8 \u6267\u884c\u3002<samp>Continuation<\/samp><samp>AsyncSOAPStockQuoteService<\/samp><samp>AsyncSOAPStockQuoteService<\/samp><samp>beginStockQuote<\/samp><samp>beginStockQuote<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public Continuation startRequest() {\n   Integer TIMEOUT_INT_SECS = 60;  \n   Continuation cont = new Continuation(TIMEOUT_INT_SECS);\n   cont.continuationMethod = 'processResponse';\n   \n   AsyncSOAPStockQuoteService.AsyncStockQuoteServiceSoap \n      stockQuoteService = \n        new AsyncSOAPStockQuoteService.AsyncStockQuoteServiceSoap();\n   stockQuoteFuture = stockQuoteService.beginStockQuote(cont,'CRM');    \n\n   return cont;   \n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u5f53\u5916\u90e8\u670d\u52a1\u8fd4\u56de\u5f02\u6b65\u6807\u6ce8\uff08\u65b9\u6cd5\uff09\u7684\u54cd\u5e94\u65f6\uff0c\u6b64\u56de\u8c03\u65b9\u6cd5\u662f \u6267\u884c\u3002\u5b83\u901a\u8fc7\u8c03\u7528\u54cd\u5e94\u5bf9\u8c61\u4e0a\u7684\u65b9\u6cd5\u6765\u83b7\u53d6\u54cd\u5e94\u3002<samp>beginStockQuote<\/samp><samp>getValue<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public Object processResponse() {\n   result = stockQuoteFuture.getValue();\n   return null; \n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u4ee5\u4e0b\u662f\u5e26\u6709 action \u548c callback \u65b9\u6cd5\u7684\u6574\u4e2a\u63a7\u5236\u5668\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class ContinuationSOAPController {\n \n    AsyncSOAPStockQuoteService.GetStockQuoteResponse_elementFuture\n           stockQuoteFuture;\n    public String result {get;set;}\n\n    \/\/ Action method\n    public Continuation startRequest() {    \n       Integer TIMEOUT_INT_SECS = 60;  \n       Continuation cont = new Continuation(TIMEOUT_INT_SECS);\n       cont.continuationMethod = 'processResponse';\n       \n       AsyncSOAPStockQuoteService.AsyncStockQuoteServiceSoap \n          stockQuoteService = \n            new AsyncSOAPStockQuoteService.AsyncStockQuoteServiceSoap();\n           stockQuoteFuture = stockQuoteService.beginGetStockQuote(cont,'CRM');     \n       return cont;   \n    }    \n    \n    \/\/ Callback method\n    public Object processResponse() {    \n       result = stockQuoteFuture.getValue();\n       \/\/ Return null to re-render the original Visualforce page\n       return null; \n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u663e\u793a\u4e86\u8c03\u7528\u8be5\u65b9\u6cd5\u5e76\u663e\u793a\u7ed3\u679c\u7684\u76f8\u5e94 Visualforce \u9875\u9762 \u7530\u3002<samp>startRequest<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;apex:page controller=\"ContinuationSOAPController\" showChat=\"false\" showHeader=\"false\"&gt;\n   &lt;apex:form &gt;      \n      &lt;!-- Invokes the action method when the user clicks this button. --&gt;\n      &lt;apex:commandButton action=\"{!startRequest}\" \n              value=\"Start Request\" reRender=\"result\"\/&gt; \n   &lt;\/apex:form&gt;\n\n   &lt;!-- This output text component displays the callout response body. --&gt;\n   &lt;apex:outputText value=\"{!result}\" \/&gt;\n&lt;\/apex:page&gt;<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u6d4b\u8bd5\u57fa\u4e8e WSDL \u7684\u5f02\u6b65\u6807\u6ce8<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">\u6d4b\u8bd5\u57fa\u4e8e WSDL \u4e2d\u7684 Apex \u7c7b\u7684\u5f02\u6b65\u6807\u6ce8\u4e0e\u6b64\u7c7b\u4f3c \u6dfb\u52a0\u5230\u4e0e\u57fa\u4e8e\u7c7b\u7684\u6807\u6ce8\u4e00\u8d77\u4f7f\u7528\u7684\u6d41\u7a0b\u3002\u5728\u6d4b\u8bd5&nbsp;ContinuationSOAPController.cls&nbsp;\u4e4b\u524d\uff0c\u8bf7\u521b\u5efa\u4e00\u4e2a \u5b9e\u73b0\u3002\u672c\u7c7b \u542f\u7528\u5bf9&nbsp;ContinuationTestForWSDL.cls&nbsp;\u7684\u5b89\u5168\u6d4b\u8bd5\uff0c\u8be5\u6d4b\u8bd5 \u6211\u4eec\u7a0d\u540e\u5c06\u901a\u8fc7\u542f\u7528\u6a21\u62df\u5ef6\u7eed\u5e76\u786e\u4fdd \u6d4b\u8bd5\u6ca1\u6709\u5b9e\u9645\u6548\u679c\u3002<samp>HttpRequest<\/samp><samp>WebServiceMock<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>public class AsyncSOAPStockQuoteServiceMockImpl implements WebServiceMock {\n    public void doInvoke(\n        Object stub, \n        Object request, \n        Map&lt;String, Object&gt; response,\n        String endpoint, \n        String soapAction, \n        String requestName,\n        String responseNS, \n        String responseName, \n        String responseType) {\n        \/\/ do nothing\n    }\n}<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">\u6b64\u793a\u4f8b\u662f\u5bf9\u5e94\u4e8e\u63a7\u5236\u5668\u7684\u6d4b\u8bd5\u7c7b\u3002\u7c7b\u4e2d\u7684\u6d4b\u8bd5\u65b9\u6cd5 \u8bbe\u7f6e\u4e00\u4e2a\u5047\u54cd\u5e94\u5e76\u8c03\u7528\u4e00\u4e2a\u6a21\u62df\u7684\u5ef6\u7eed\u3002\u6807\u6ce8\u4e0d\u4f1a\u53d1\u9001\u5230 \u5916\u90e8\u670d\u52a1\u3002\u4e3a\u4e86\u6267\u884c\u6a21\u62df\u6807\u6ce8\uff0c\u6d4b\u8bd5\u8c03\u7528\u7c7b\u7684\u4ee5\u4e0b\u65b9\u6cd5\uff1aTest.setContinuationResponse\uff08\uff09 \u548c Test.invokeContinuationMethod\uff08\uff09\u3002<samp>ContinuationSOAPControllerTest<\/samp><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>@isTest\npublic class ContinuationTestingForWSDL {\n    public static testmethod void testWebService() {\n\n        ContinuationSOAPController demoWSDLClass = \n            new ContinuationSOAPController();\n\n        \/\/ Invoke the continuation by calling the action method\n        Continuation conti = demoWSDLClass.startRequest();\n\n        \/\/ Verify that the continuation has the proper requests\n        Map&lt;String, HttpRequest&gt; requests = conti.getRequests();\n        System.assertEquals(requests.size(), 1);\n\n        \/\/ Perform mock callout \n        \/\/ (i.e. skip the callout and call the callback method)\n        HttpResponse response = new HttpResponse();\n        response.setBody('&lt;SOAP:Envelope'\n            + ' xmlns:SOAP=\"http:\/\/schemas.xmlsoap.org\/soap\/envelope\/\"&gt;'\n            + '&lt;SOAP:Body&gt;'\n            + '&lt;m:getStockQuoteResponse '\n            + 'xmlns:m=\"http:\/\/soap.sforce.com\/schemas\/class\/StockQuoteServiceSoap\"&gt;'\n            + '&lt;m:result&gt;Mock response body&lt;\/m:result&gt;' \n            + '&lt;\/m:getStockQuoteResponse&gt;' \n            + '&lt;\/SOAP:Body&gt;'\n            + '&lt;\/SOAP:Envelope&gt;');\n\n        \/\/ Set the fake response for the continuation\n        String requestLabel = requests.keyset().iterator().next();\n        Test.setContinuationResponse(requestLabel, response);\n\n        \/\/ Invoke callback method\n        Object result = Test.invokeContinuationMethod(demoWSDLClass, conti);\n        System.debug(demoWSDLClass);\n\n        \/\/ result is the return value of the callback\n        System.assertEquals(null, result);\n\n        \/\/ Verify that the controller's result variable\n        \/\/   is set to the mock response.\n        System.assertEquals('Mock response body', demoWSDLClass.result);\n    }\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Apex \u5141\u8bb8\u60a8\u4f7f\u7528\u6807\u6ce8\u4e0e\u5916\u90e8 SOAP \u548c REST Web \u670d\u52a1\u96c6\u6210\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u7528\u4e8e JSON\u3001XML\u3001\u6570\u636e\u5b89\u5168\u548c\u7f16\u7801\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u901a\u7528\u5b9e\u7528\u7a0b\u5e8f \u5bf9\u4e8e\u5e26\u6709\u6587\u672c\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e5f\u63d0\u4f9b\u4e86\u3002<\/p>\n","protected":false},"author":1,"featured_media":3758,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[199],"tags":[224],"class_list":["post-3757","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-apex-","tag--apex-"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v21.7 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f - \u767d\u767d\u968f\u7b14<\/title>\n<meta name=\"description\" content=\"Apex \u5141\u8bb8\u60a8\u4f7f\u7528\u6807\u6ce8\u4e0e\u5916\u90e8 SOAP \u548c REST Web \u670d\u52a1\u96c6\u6210\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u7528\u4e8e JSON\u3001XML\u3001\u6570\u636e\u5b89\u5168\u548c\u7f16\u7801\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u901a\u7528\u5b9e\u7528\u7a0b\u5e8f \u5bf9\u4e8e\u5e26\u6709\u6587\u672c\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e5f\u63d0\u4f9b\u4e86\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=3757\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f - \u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"og:description\" content=\"Apex \u5141\u8bb8\u60a8\u4f7f\u7528\u6807\u6ce8\u4e0e\u5916\u90e8 SOAP \u548c REST Web \u670d\u52a1\u96c6\u6210\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u7528\u4e8e JSON\u3001XML\u3001\u6570\u636e\u5b89\u5168\u548c\u7f16\u7801\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u901a\u7528\u5b9e\u7528\u7a0b\u5e8f \u5bf9\u4e8e\u5e26\u6709\u6587\u672c\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e5f\u63d0\u4f9b\u4e86\u3002\" \/>\n<meta property=\"og:url\" content=\"http:\/\/www.ponybai.com\/?p=3757\" \/>\n<meta property=\"og:site_name\" content=\"\u767d\u767d\u968f\u7b14\" \/>\n<meta property=\"article:published_time\" content=\"2023-12-24T13:29:40+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-11-27T13:32:42+00:00\" \/>\n<meta property=\"og:image\" content=\"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/11\/HttpRequest.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1002\" \/>\n\t<meta property=\"og:image:height\" content=\"288\" \/>\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=\"15 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3757#article\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3757\"},\"author\":{\"name\":\"ponybai\",\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"headline\":\"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f\",\"datePublished\":\"2023-12-24T13:29:40+00:00\",\"dateModified\":\"2023-11-27T13:32:42+00:00\",\"mainEntityOfPage\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3757\"},\"wordCount\":1305,\"publisher\":{\"@id\":\"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883\"},\"keywords\":[\"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f\"],\"articleSection\":[\"Apex \u5f00\u53d1\u4eba\u5458\u6307\u5357\"],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"WebPage\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3757\",\"url\":\"http:\/\/www.ponybai.com\/?p=3757\",\"name\":\"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f - \u767d\u767d\u968f\u7b14\",\"isPartOf\":{\"@id\":\"http:\/\/www.ponybai.com\/#website\"},\"datePublished\":\"2023-12-24T13:29:40+00:00\",\"dateModified\":\"2023-11-27T13:32:42+00:00\",\"description\":\"Apex \u5141\u8bb8\u60a8\u4f7f\u7528\u6807\u6ce8\u4e0e\u5916\u90e8 SOAP \u548c REST Web \u670d\u52a1\u96c6\u6210\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u7528\u4e8e JSON\u3001XML\u3001\u6570\u636e\u5b89\u5168\u548c\u7f16\u7801\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u901a\u7528\u5b9e\u7528\u7a0b\u5e8f \u5bf9\u4e8e\u5e26\u6709\u6587\u672c\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e5f\u63d0\u4f9b\u4e86\u3002\",\"breadcrumb\":{\"@id\":\"http:\/\/www.ponybai.com\/?p=3757#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"http:\/\/www.ponybai.com\/?p=3757\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"http:\/\/www.ponybai.com\/?p=3757#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"http:\/\/www.ponybai.com\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f\"}]},{\"@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":"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f - \u767d\u767d\u968f\u7b14","description":"Apex \u5141\u8bb8\u60a8\u4f7f\u7528\u6807\u6ce8\u4e0e\u5916\u90e8 SOAP \u548c REST Web \u670d\u52a1\u96c6\u6210\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u7528\u4e8e JSON\u3001XML\u3001\u6570\u636e\u5b89\u5168\u548c\u7f16\u7801\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u901a\u7528\u5b9e\u7528\u7a0b\u5e8f \u5bf9\u4e8e\u5e26\u6709\u6587\u672c\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e5f\u63d0\u4f9b\u4e86\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=3757","og_locale":"zh_CN","og_type":"article","og_title":"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f - \u767d\u767d\u968f\u7b14","og_description":"Apex \u5141\u8bb8\u60a8\u4f7f\u7528\u6807\u6ce8\u4e0e\u5916\u90e8 SOAP \u548c REST Web \u670d\u52a1\u96c6\u6210\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u7528\u4e8e JSON\u3001XML\u3001\u6570\u636e\u5b89\u5168\u548c\u7f16\u7801\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u901a\u7528\u5b9e\u7528\u7a0b\u5e8f \u5bf9\u4e8e\u5e26\u6709\u6587\u672c\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e5f\u63d0\u4f9b\u4e86\u3002","og_url":"http:\/\/www.ponybai.com\/?p=3757","og_site_name":"\u767d\u767d\u968f\u7b14","article_published_time":"2023-12-24T13:29:40+00:00","article_modified_time":"2023-11-27T13:32:42+00:00","og_image":[{"width":1002,"height":288,"url":"http:\/\/www.ponybai.com\/wp-content\/uploads\/2023\/11\/HttpRequest.png","type":"image\/png"}],"author":"ponybai","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"ponybai","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"15 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"http:\/\/www.ponybai.com\/?p=3757#article","isPartOf":{"@id":"http:\/\/www.ponybai.com\/?p=3757"},"author":{"name":"ponybai","@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"headline":"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f","datePublished":"2023-12-24T13:29:40+00:00","dateModified":"2023-11-27T13:32:42+00:00","mainEntityOfPage":{"@id":"http:\/\/www.ponybai.com\/?p=3757"},"wordCount":1305,"publisher":{"@id":"http:\/\/www.ponybai.com\/#\/schema\/person\/935c7592c850c65e1e5eba4530dbf883"},"keywords":["\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f"],"articleSection":["Apex \u5f00\u53d1\u4eba\u5458\u6307\u5357"],"inLanguage":"zh-Hans"},{"@type":"WebPage","@id":"http:\/\/www.ponybai.com\/?p=3757","url":"http:\/\/www.ponybai.com\/?p=3757","name":"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f - \u767d\u767d\u968f\u7b14","isPartOf":{"@id":"http:\/\/www.ponybai.com\/#website"},"datePublished":"2023-12-24T13:29:40+00:00","dateModified":"2023-11-27T13:32:42+00:00","description":"Apex \u5141\u8bb8\u60a8\u4f7f\u7528\u6807\u6ce8\u4e0e\u5916\u90e8 SOAP \u548c REST Web \u670d\u52a1\u96c6\u6210\u3002 \u60a8\u53ef\u4ee5\u4f7f\u7528\u7528\u4e8e JSON\u3001XML\u3001\u6570\u636e\u5b89\u5168\u548c\u7f16\u7801\u7684\u5b9e\u7528\u7a0b\u5e8f\u3002\u901a\u7528\u5b9e\u7528\u7a0b\u5e8f \u5bf9\u4e8e\u5e26\u6709\u6587\u672c\u5b57\u7b26\u4e32\u7684\u6b63\u5219\u8868\u8fbe\u5f0f\uff0c\u4e5f\u63d0\u4f9b\u4e86\u3002","breadcrumb":{"@id":"http:\/\/www.ponybai.com\/?p=3757#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["http:\/\/www.ponybai.com\/?p=3757"]}]},{"@type":"BreadcrumbList","@id":"http:\/\/www.ponybai.com\/?p=3757#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"http:\/\/www.ponybai.com\/"},{"@type":"ListItem","position":2,"name":"\u96c6\u6210\u548c Apex \u5b9e\u7528\u7a0b\u5e8f"}]},{"@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\/3757","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=3757"}],"version-history":[{"count":2,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3757\/revisions"}],"predecessor-version":[{"id":3760,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/posts\/3757\/revisions\/3760"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=\/wp\/v2\/media\/3758"}],"wp:attachment":[{"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3757"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3757"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ponybai.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3757"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}