0

我正在使用 Salesforce REST API。我在 SFDC 中创建了一个新的自定义对象,并希望向其发布数据。我可以愉快地将 JSON 文档发布到标准 SFDC 对象,例如 Account 或 Contact。但是,当我尝试发布到我的自定义对象时,我收到了来自 SFDC 的超时。

这是我用来执行所有 POSTS 的方法(无论是标准的还是自定义的)

public static BsonDocument PostJSONToSFDC(string uri, BsonDocument postDoc, string method, HPSUtilities.Transformation.Transformation transformation)
        {
            string accessToken = transformation.sfdcAccess.accessToken;
            string instanceUri = transformation.sfdcAccess.instanceUri;

            string uri2 = instanceUri + uri;

            System.Net.WebRequest req = System.Net.WebRequest.Create(uri2);
            req.ContentType = "application/json";
            req.Method = method;// "POST" or "PATCH"; // a PATCH alternative uses POST with url parm="?_HttpMethod=PATCH"
            req.Headers.Add("Authorization: Bearer " + accessToken);

            string postDocAsString = postDoc.ToJson();

            byte[] bytes = System.Text.Encoding.ASCII.GetBytes(postDocAsString);
            req.ContentLength = bytes.Length;
            System.IO.Stream os = req.GetRequestStream();
            os.Write(bytes, 0, bytes.Length); //Push it out there
            os.Close();
            System.Net.WebResponse resp = req.GetResponse();
            if (resp == null) return null;
            System.IO.StreamReader sr =
                  new System.IO.StreamReader(resp.GetResponseStream());

            string rs = sr.ReadToEnd().Trim();
            MongoDB.Bson.BsonDocument doc2;
            if (rs.Equals("") && method.Equals("PATCH", StringComparison.CurrentCultureIgnoreCase))
            {
                // For successful PATCHs (updates), SFDC mysteriously returns a completely empty response.
                // In this case let's create something more meaningful!
                doc2 = new BsonDocument();
                doc2.Add("success", "true");
            }
            else
            {
                doc2 = MongoDB.Bson.Serialization.BsonSerializer.Deserialize<MongoDB.Bson.BsonDocument>(rs);

            }

            return doc2;
        }

鉴于此代码在向 SFDC 发布或修补时有效,我相信我必须为自定义对象遇到某种 SFDC 限制。是否有必要将 SFDC 自定义对象标记为启用 API?有人知道可能导致我超时的任何其他问题吗?

4

0 回答 0