分类

链接

2018 年 3 月
 1234
567891011
12131415161718
19202122232425
262728293031  

近期文章

热门标签

新人福利,免费薅羊毛

现在位置:    首页 > Salesforce > 正文
共享办公室出租
eclipse调用salseforce soap api
Salesforce 暂无评论 阅读(514)

内容参考:

https://resources.docs.salesforce.com/202/latest/en-us/sfdc/pdf/salesforce_developer_environment_tipsheet.pdf

https://www.cnblogs.com/zero-zyq/p/6077773.html

具体步骤:

1.下载Force.com Web Service Connector

下载链接为http://mvnrepository.com/artifact/com.force.api/force-wsc

2.下载开发的WSDL文件

Setup->Build->API,这里有很多可以选择的WSDL,企业级WSDL,合作伙伴,元信息等。此处选择企业级WSDL,选择以后详情页右键另存为MyProject.wsdl,名字随便起

不同WSDL区别:https://developer.salesforce.com/docs/atlas.en-us.202.0.api.meta/api/sforce_api_quickstart_intro.htm#choose_wsdl

3.下载Rhino JavaScript framework,下载完rar文件以后选择其中的js.jar

https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Download_Rhino

4.下载StringTemplate engine framework ,我选择的是目前最新的4.0.8.jar

http://www.stringtemplate.org/download.html

5.下载ANTRL runtime,我下载的是最新的版本的complete模式,其他模式有可能缺少相关的类

http://www.antlr.org/download.html

6.生成myproject.jar,将上述jar包以及myproject.wsdl放置在C:\Users\test\Desktop\myproject目录下,打开控制台cmd

java -classpath force-wsc-42.0.0.jar;ST4-4.0.8.jar;antlr-4.7.1-complete.jar;js.jar com.sforce.ws.tools.wsdlc phonesalesystem.wsdl phonesalesystem.jar

7.使用force-wsc-38.04.jar以及生成的myproject.jar实现java通过soap api方式访问sfdc,使用soap api访问有很多限制,比如一次insert或者upsert不能超过200等,这里举例登录以及批量添加功能。

限制详情:https://developer.salesforce.com/docs/atlas.en-us.204.0.salesforce_app_limits_cheatsheet.meta/salesforce_app_limits_cheatsheet/salesforce_app_limits_platform_apicalls.htm

SOAP API : https://resources.docs.salesforce.com/204/latest/en-us/sfdc/pdf/apex_api.pdf

  1. public class Test {
  2.     static final String USERNAME = "xxx";
  3.     static final String PASSWORD = "xxxx";
  4.     static EnterpriseConnection connection;
  5.     static List<Brand__c> brandList;
  6.  
  7.     public static void main(String[] args) throws NoSuchAlgorithmException   {
  8.  
  9.         ConnectorConfig config = new ConnectorConfig();
  10.         config.setUsername(USERNAME);
  11.         config.setPassword(PASSWORD);
  12.  
  13.         try {  
  14.             //SSLContext CTX = SSLContext.getInstance("SSL");
  15.             //SSLContext.setDefault(CTX);
  16.             //  SSLContext sc = SSLContext.getInstance("SSLv3");
  17.              //String result = httpsRequest("https://blog.peos.cn","GET",null);
  18.              //System.out.println(result);
  19.              
  20.              
  21.             String authEndPoint = "https://login.salesforce.com/services/Soap/c/42.0";
  22.             //System.out.println("AuthEndPoint: " + authEndPoint);
  23.             config.setAuthEndpoint(authEndPoint);
  24.  
  25.             @SuppressWarnings("static-access")
  26.             Proxy proxy = new Proxy(Proxy.Type.DIRECT.HTTP, new InetSocketAddress(proxyHost, proxyPort));
  27.             
  28.             config.setProxy(proxy);
  29.             connection = new EnterpriseConnection(config);
  30.             connection = Connector.newConnection(config);
  31.             System.out.println("Auth EndPoint: " + config.getAuthEndpoint());
  32.             System.out.println("Service EndPoint: " + config.getServiceEndpoint());
  33.             System.out.println("Username: " + config.getUsername());
  34.             System.out.println("SessionId: " + config.getSessionId());
  35.  
  36.             // brandList =
  37.             querySample();
  38.  
  39.         } catch ( Exception e1) {
  40.             e1.printStackTrace();
  41.         }
  42.     }
  43.  
  44.     private static void querySample() {
  45.         String soqlQuery = "SELECT FirstName, LastName FROM Contact";
  46.         try {
  47.             QueryResult qr = connection.query(soqlQuery);
  48.             boolean done = false;
  49.             if (qr.getSize() > 0) {
  50.                 System.out.println("\nLogged-in user can see " + qr.getRecords().length + " contact records.");
  51.                 while (!done) {
  52.                     System.out.println("");
  53.                     Contact[] records = (Contact[]) qr.getRecords();
  54.                     for (int i = 0; i < records.length; ++i) {
  55.                         Contact con = (Contact) records[i];
  56.                         String fName = con.getFirstName();
  57.                         String lName = con.getLastName();
  58.                         if (fName == null) {
  59.                             System.out.println("Contact " + (+ 1) + ": " + lName);
  60.                         } else {
  61.                             System.out.println("Contact " + (+ 1) + ": " + fName + " " + lName);
  62.                         }
  63.                     }
  64.                     if (qr.isDone()) {
  65.                         done = true;
  66.                     } else {
  67.                         qr = connection.queryMore(qr.getQueryLocator());
  68.                     }
  69.                 }
  70.  
  71.             } else {
  72.                 System.out.println("No records found.");
  73.             }
  74.         } catch (ConnectionException ce) {
  75.             ce.printStackTrace();
  76.         }
  77.     }
  78.      
  79.     private static String proxyHost = "10.248.60.204";
  80.     private static int proxyPort = 3266;
  81.  
  82. }
  83.     

 

常见问题:

1.JDK版本为1.6,1.7的,会报STL1.2的错误,请升级JDK为1.8+

2.升级JDK仍然报错的,请使用代理链接(见代码,我就是因为没有设置代码,一直以为是STL没有配置好走了很久的弯路)

 

 

============ 欢迎各位老板打赏~ ===========

本文版权归Bruce's Blog所有,转载引用请完整注明以下信息:
本文作者:Bruce
本文地址:eclipse调用salseforce soap api | Bruce's Blog

发表评论

留言无头像?