Salesforce:如何使用java为Geolocation数据类型字段插入值?

时间:2012-12-13 14:43:10

标签: salesforce force.com

我使用REST API将对象插入salesforce。我有一个Geolocation数据类型的字段。 如何使用java插入这个字段的值?我的示例代码如下。

parishud.put( “gps__c” ?????);

要插入两个字段(gps(纬度)gps(经度))但在API中我只找到一个名为gps__c的字段

  HttpClient client = new httpclient.HttpClient();
  JSONObject parishud = new JSONObject();
  try {
      parishud.put("Name","ParishudhTest4");
      parishud.put("entitled__c","Yes");

      parishud.put("Comments__c","Comments");
      parishud.put("fallill_count_after__c","5");
      parishud.put("fallill_count_before__c","7");
      parishud.put("influencedcount__c","8");
      parishud.put("toiletusaseperday__c","3");
      parishud.put("parishudhid__c","002");
      parishud.put("Received_NBA_Incentive__c","Yes");
      parishud.put("Received_NREGA_Incentive__c","Yes");

      //parishud.put("gps__c",?????);


    PostMethod postaccount = new PostMethod("https://ap1.salesforce.com/services/data/v20.0/sobjects/Parishudh__c/");
    postaccount.setRequestHeader("Authorization", "OAuth " + accessToken);
    postaccount.setRequestEntity(new StringRequestEntity(parishud.toString(),"application/json", null));
    client.executeMethod(postaccount);

1 个答案:

答案 0 :(得分:1)

Geolocation字段实际上由3个字段组成,其中2个字段可供我们访问。

如果您的字段名称为gps,那么您可以将数据存储在gps__Latitude__sgps__Longitude__s中(请注意开头的双下划线,因为它是托管包,结尾是“s” “,而不是”c“)。

确保为Java集成用户设置了配置文件级安全性,以便能够访问此字段。

如果您需要代码示例 - 您可以查看我的回答How do I integrate Salesforce with Google Maps?或例如http://blog.internetcreations.com/2012/09/creating-a-geolocation-trigger-in-salesforce-winter-13/