簡體   English   中英

調用Salesforce標准REST API以及通過自定義REST Apex查詢時在響應方面有所不同

[英]Getting difference in response when calling salesforce standard REST api and when querying the same through Custom REST apex

當我查詢salesforce REST API (/services/data/v29.0/query?q=select+id,Name,AccountNumber,OwnerId,Site,Description,NumberOfEmployees,Fax,Industry,Phone,Website,Type+from+Account+where+id='0019000000NMrbv')我得到以下響應。

{
    "attributes" : {
      "type" : "Account",
      "url" : "/services/data/v29.0/sobjects/Account/0019000000NMrbvAAD"
    },
    "Id" : "0019000000NMrbvAAD",
    "Name" : "Test G",
    "AccountNumber" : null,
    "OwnerId" : "00590000001BpGnAAK",
    "Site" : null,
    "Description" : null,
    "NumberOfEmployees" : null,
    "Fax" : null,
    "Industry" : null,
    "Phone" : null,
    "Website" : null,
    "Type" : null
}

現在我創建了如下的apex rest服務,與上面的查詢相同

@HttpGet
 global static Account doGet(){
    Account acc = [select id,Name,AccountNumber,OwnerId,Site,Description,NumberOfEmployees,Fax,Industry,Phone,Website,Type from Account where id ='0019000000NMrbvAAD'];
    return acc;
}

當我致電此服務時得到的響應是

{
   "attributes":    {
      "type": "Account",
      "url": "/services/data/v29.0/sobjects/Account/0019000000NMrbvAAD"
   },
   "Name": "Test G",
   "OwnerId": "00590000001BpGnAAK",
   "Id": "0019000000NMrbvAAD"
}

現在,請比較上述兩個響應。apex rest服務的響應沒有字段為空值。

我們已經創建了一個salesforce ios本地應用程序。 該服務使用標准的REST api,但是由於性能問題,我們正計划創建APEX rest服務,但是由於響應方面的差異,我們將不得不在許多地方更改代碼來處理此問題。

有沒有人遇到過這樣的問題,如果您建議如何解決這個問題,這會有所幫助嗎? 我們可以做些什么,以便apex rest服務返回與標准saleforce REST api相同的響應。

我們已經注意到Salesforce序列化中的類似行為。 通常根本不包含空對象。

API可能使用了自己的序列化器。

無論如何,您並不孤單。

https://salesforce.stackexchange.com/questions/13820/json-serialize-method-not-returning-null-fields-part-deux

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM