嗨我很难将数据插入到salesforce对象中,从我的Android应用程序中我想将数据插入到Sobject中,实现如下:
private void sendOrderRequest() throws UnsupportedEncodingException {
final String externalIdField = "OrderExtID__c";
final String externalId = "123";
final String accountType = SalesforceSDKManager.getInstance().getAccountType();
final LoginOptions loginOptions = SalesforceSDKManager.getInstance().getLoginOptions();
new ClientManager(getActivity(), accountType, loginOptions, SalesforceSDKManager.getInstance().shouldLogoutWhenTokenRevoked()).getRestClient(getActivity(), new RestClientCallback() {
@Override
public void authenticatedRestClient(RestClient client) {
if (client == null) {
SalesforceSDKManager.getInstance().logout(getActivity());
return;
}
// 'client' is a valid rest client.
RestRequest restRequest = null;
try {
HashMap<String, Object> fields = new HashMap<String, Object>();
fields.put(CREATEDBY, createdby.getText().toString());
fields.put(CREATEDDATE, createddate.getText().toString());
fields.put(ORDERID, orderid.getText().toString());
fields.put(PRODUCTID, productid.getText().toString());
fields.put(QUANTITY, quantity.getText().toString());
fields.put(PRICE, price.getText().toString());
fields.put(DESCRIPTION, description.getText().toString());
restRequest = RestRequest.getRequestForUpsert(getString(R.string.api_version), getString(R.string.objecttype),externalIdField,externalId, fields);
} catch (UnsupportedEncodingException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
// restRequest = RestRequest.getRequestForDescribeGlobal(getString(R.string.api_version));
client.sendAsync(restRequest, new AsyncRequestCallback() {
@Override
public void onSuccess(RestRequest request, RestResponse result) {
try {
System.out.println("successsss");
System.out.println("Result..printinf ===="+result.asJSONObject().getJSONArray("sobjects"));
EventsObservable.get().notifyEvent(EventType.RenditionComplete);
} catch (Exception e) {
onError(e);
}
}
我收到错误:404,有人可以指出我正确的方向,getRequestForUpsert()
要求externalIdfeild
和external id
,我是否通过请求核心方式?蚂蚁帮助非常感谢
答案 0 :(得分:0)
如果问题如前所述,您的错误消息表明您未提供已识别的externalIdField或externalId,则可能是因为您尝试通过REST请求执行UPSERT操作。 UPSERT是Force.com数据操作语言(DML)操作,它将尝试通过首先对其ID进行查找来确定您提交的记录(salesforce对象)是否已经在数据库中。它允许在salesforce ID(记录的PK)或标记为ExternalId的备用候选键字段(通常来自记录的外部数据表)上进行查找,但还要求您确定应将哪个字段用作键; Id或ExternalId字段。如果您只需要执行插入,请尝试替换调用getRequestForCreate()方法。以下是RestRequest的REST文档页面的链接: