SForceAPI:无法找到 API 上列出的类? (帐户、联系方式等)

发布于 2024-10-09 14:21:30 字数 632 浏览 3 评论 0原文

API 引用:http://www.salesforce.com/us/developer/文档/api/index.htm
小节:参考->标准对象

客户端详细信息:partner.wsdl,Axis2 1.5, 使用解压选项(-u)生成存根。

我希望找到一些基本对象,例如帐户、联系人等(在上面的网址中列出),以便我可以执行类似

-> SObject[] sObjArray = queryResult.getRecords(); 

   for(SObject sObj : sObjArray){
     Account acc = [Account] sObj; 
   }

[在另一个网络服务中成功使用上述方法 - 'Zuora'] 的操作,

但是,我找不到帐户类在生成的类中。我想我的方法是错误的,但至少我应该找到参考 API 中列出的类。

请帮忙。

API referred : http://www.salesforce.com/us/developer/docs/api/index.htm
subsection: reference->standard objects

Client side details : partner.wsdl, Axis2 1.5,
generated stubs using unpacked option (-u).

I was hoping to find some basic objects like Account, Contact, etc (which were listed on above url) so that I can do something like

-> SObject[] sObjArray = queryResult.getRecords(); 

   for(SObject sObj : sObjArray){
     Account acc = [Account] sObj; 
   }

[used above approach successfully in another webservice - 'Zuora']

However, I could not find Account class in the generated classes. I guess I am into wrong approach, but atleast I should be finding the classes listed in the reference API.

Please help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

一城柳絮吹成雪 2024-10-16 14:21:30

合作伙伴 WSDL 有一个松散类型的数据模型,允许与任何组织的数据进行交互,而无需提前了解其模式 - 您只需获取 SObject。相比之下,企业 WSDL 是强类型的,并且具有您正在寻找的帐户、联系人等类型 - 请参阅 http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_partner.htm

另外,由于您生成了企业为您的组织按需提供 WSDL,它包括您的自定义类型(或 Salesforce 术语中的对象)。

[已更新以回答评论...]

我生成了存根,

wsdl2java.sh -uri ~/soapclient/partner.wsdl.xml -p com.superpat.partner -d adb -u -s

我不是 Axis2 专家,但我将以下内容组合在一起,它似乎有效:

package axis2partner;

import com.sforce.soap.partner.Login;
import com.sforce.soap.partner.LoginResult;
import com.sforce.soap.partner.Query;
import com.sforce.soap.partner.QueryResult;
import com.sforce.soap.partner.SessionHeader;
import com.sforce.soap.partner.sobject.SObject;
import com.superpat.partner.SforceServiceStub;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.axiom.om.OMElement;

public class Main {
    private static String username = "[email protected]";
    private static String password = "password";
    private static String securityToken = "SECURITY_TOKEN";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // First, login to get a session ID and server URL
            SforceServiceStub loginStub = new SforceServiceStub();

            Login login = new Login();

            login.setUsername(username);
            login.setPassword(password + securityToken);

            LoginResult loginResult
                    = loginStub.login(login, null, null).getResult();

            // Now make a stub for the correct service instance
            SforceServiceStub serviceStub
                    = new SforceServiceStub(loginResult.getServerUrl());

            SessionHeader sessionHeader = new SessionHeader();
            sessionHeader.setSessionId(loginResult.getSessionId());

            // Now we can execute the actual query
            Query query = new Query();
            query.setQueryString("SELECT Id, Name, AccountNumber, BillingCity,"
                    + " BillingState, Description FROM Account");

            QueryResult queryResult = serviceStub.query(query, sessionHeader,
                    null, null, null, null).getResult();

            SObject[] sObjArray = queryResult.getRecords();

            for ( SObject sObj : sObjArray ) {
                System.out.println(sObj.getId());
                for ( OMElement omElement : sObj.getExtraElement() ) {
                    System.out.println("\t" + omElement.getLocalName() + ": "
                            + omElement.getText());
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

在我的开发组织中,这会产生以下形式的输出:

0015000000VALE3AAP
    Id: 0015000000VALE3AAP
    Name: United Oil & Gas Corp.
    AccountNumber: CD355118
    BillingCity: New York
    BillingState: NY
    Description: World's third largest oil and gas company.

注意 - 原始 SOAP界面非常通用,并不是使用 Force.com API 的最简单方法。您可能需要查看 Force.com Web 服务连接器。还有一个 REST API,但它目前(2011 年 1 月)处于开发者预览版,不适用于生产部署。

The partner WSDL has a loosely-typed data model that allows interaction with any organization's data without its schema being known in advance - you just get SObjects. In contrast, the enterprise WSDL is strongly typed, and has the Account, Contact etc types you are looking for - see http://www.salesforce.com/us/developer/docs/api/Content/sforce_api_partner.htm

Also, since you generate the enterprise WSDL on demand for your org, it includes your custom types (or objects, in Salesforce parlance).

[Updated to answer comment...]

I generated stubs with

wsdl2java.sh -uri ~/soapclient/partner.wsdl.xml -p com.superpat.partner -d adb -u -s

I'm not an Axis2 expert, but I hacked the following together and it seems to work:

package axis2partner;

import com.sforce.soap.partner.Login;
import com.sforce.soap.partner.LoginResult;
import com.sforce.soap.partner.Query;
import com.sforce.soap.partner.QueryResult;
import com.sforce.soap.partner.SessionHeader;
import com.sforce.soap.partner.sobject.SObject;
import com.superpat.partner.SforceServiceStub;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.axiom.om.OMElement;

public class Main {
    private static String username = "[email protected]";
    private static String password = "password";
    private static String securityToken = "SECURITY_TOKEN";

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        try {
            // First, login to get a session ID and server URL
            SforceServiceStub loginStub = new SforceServiceStub();

            Login login = new Login();

            login.setUsername(username);
            login.setPassword(password + securityToken);

            LoginResult loginResult
                    = loginStub.login(login, null, null).getResult();

            // Now make a stub for the correct service instance
            SforceServiceStub serviceStub
                    = new SforceServiceStub(loginResult.getServerUrl());

            SessionHeader sessionHeader = new SessionHeader();
            sessionHeader.setSessionId(loginResult.getSessionId());

            // Now we can execute the actual query
            Query query = new Query();
            query.setQueryString("SELECT Id, Name, AccountNumber, BillingCity,"
                    + " BillingState, Description FROM Account");

            QueryResult queryResult = serviceStub.query(query, sessionHeader,
                    null, null, null, null).getResult();

            SObject[] sObjArray = queryResult.getRecords();

            for ( SObject sObj : sObjArray ) {
                System.out.println(sObj.getId());
                for ( OMElement omElement : sObj.getExtraElement() ) {
                    System.out.println("\t" + omElement.getLocalName() + ": "
                            + omElement.getText());
                }
            }
        } catch (Exception ex) {
            Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}

In my dev org, this produces output of the form:

0015000000VALE3AAP
    Id: 0015000000VALE3AAP
    Name: United Oil & Gas Corp.
    AccountNumber: CD355118
    BillingCity: New York
    BillingState: NY
    Description: World's third largest oil and gas company.

NOTE - the raw SOAP interface is pretty generic, and not the easiest way to work with the Force.com API. You might want to take a look at the Force.com Web Services Connector. There is also a REST API, but it is currently (Jan 2011) in developer preview, and not for production deployment.

清风不识月 2024-10-16 14:21:30

为了添加“metadaddy”发布的响应并帮助“Firefox”以及许多其他可能偶然发现此答案的人,我想分享一些个人经验的观察结果:

  1. 使用来自 Salesforce 的合作伙伴 WSDL 非常容易。 com (SFDC) 与 Axis(例如 Axis 1.4),但很难将合作伙伴 WSDL 与 Axis2(例如 Axis2 1.5.1 或 1.6.0)一起使用。
  2. 要将合作伙伴 WSDL 与 Axis2 一起使用,您基本上需要创建从企业 WSDL 创建的对象的传真。如果您决定使用此方法,还可以从企业 WSDL 生成存根,并使用为“帐户”、“联系人”等生成的代码作为创建自定义“SObject”实例的起点。
  3. 也就是说,我的建议很简单,就是将企业 WSDL 与 Axis2 一起使用。如果您觉得必须将合作伙伴 WSDL 与某些版本的 Axis 一起使用,请将其与以前版本的 Axis 一起使用。

在谷歌上搜索一下就会发现很多人都同意我的评估。

更好的是,虽然我没有使用过它,但我建议您考虑使用 SFDC 的 REST API。

To add to the response posted by "metadaddy" and help out "Firefox" as well as the many others likely to stumble across this answer, I want to share some observations from personal experience:

  1. It's very easy to use the partner WSDL from Salesforce.com (SFDC) with Axis (e.g. Axis 1.4), but it's very difficult to use the partner WSDL with Axis2 (e.g. Axis2 1.5.1 or 1.6.0).
  2. To use the partner WSDL with Axis2, you would basically need to create facsimiles of the objects that are created from the enterprise WSDL. If you decide to use this approach, generate the stubs from the enterprise WSDL as well and use the code generated for "Account", "Contact", etc, as a starting point to create your custom "SObject" instances.
  3. That said, my recommendation, simply, is to use the enterprise WSDL with Axis2. If you feel compelled to use the partner WSDL with some version of Axis, use it with the previous version of Axis.

A search on Google will show that many people agree with my assessment.

Better yet, though I've not used it, I'd recommend looking into using SFDC's REST API instead.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文