VisualForce(APEX):使用已知 ID 更新记录
这是与 APEX 代码相关的问题,特定于 VisualForce 控制器类。
问题
我正在尝试使用已知的 AccountId 更新记录。但是,当我在 sObject 声明中设置 ID 时,SalesForce 会将字符串“IAR”附加到 ID 的末尾!
有人可以让我知道我在做什么是错误的吗?如果我以错误的方式处理此问题,那么在 fastsave() 或 update() 之外从自定义方法更新记录的正确方法是什么。
描述
所以基本上,用户将带着 id 编码来到这个页面,并且它要么有一个 id,要么有一个级别。这是由函数decode() 处理的,该函数接受一个字符串; “id”/“级别”。然后,我创建一个帐户变量“acc”,在我们使用语句“insert acc;”插入或更新帐户信息之前,该变量将用于存储所有帐户信息。因为,我无法使用“acc.id = salesForceID”设置“acc”的 ID,所以我决定在创建“acc”时设置它。当构造函数声明“acc”变量时,会出现以下 APEX 代码。
URL 变量已传递
/application?id=001Q000000OognA
APEX 控制器类(缩写)
salesForceID = decode('id');
debug1 = 'salesForceID: ' + salesForceID;
acc = new Account(id = salesForceID);
debug2 = 'Account ID: ' + acc.id;
调试输出
salesForceID: 001Q000000OognA
帐户 ID:001Q000000OognAIAR
评论
我对所给出的代码的简短表示歉意,这是出于安全原因。我基本上是在插入/更新插入/更新之前尝试设置 acc 的 ID。我感谢任何关于为什么它可以附加“IAR”的解释和/或任何更新给定输入 AccountId 的记录的替代方法。我确实明白,如果您将 id 作为 URL 变量传递,SalesForce 会自动为您执行此操作。但是,我向页面传递了多个变量,因为存在三个单独的用例。
感谢您的帮助。
This is an APEX code related question and is specific to a VisualForce controller class.
Question
I am trying to update a record with a known AccountId. However, when I set the ID in the sObject declaration SalesForce is appending the string "IAR" to the end of the ID!
Can someone please let me know what I am doing that is wrong and if I am going about this in the wrong way than what is the correct way to update a record from a custom method, outside of quicksave() or update().
Description
So basically, the user will come to this page with the id encoded and it will either have an id or a level. This is handled by the function decode() which takes a string; "id" / "level". I then create an Account variable "acc" which will be used to store all of the Account information before we insert or update it with the statement "insert acc;". Since, I cannot set the ID for "acc" with "acc.id = salesForceID" I have decided to set it when "acc" is created. The following APEX code occurs in the constructor when it is declaring the "acc" variable.
URL Variable Passed
/application?id=001Q000000OognA
APEX Controller Class (Abridged)
salesForceID = decode('id');
debug1 = 'salesForceID: ' + salesForceID;
acc = new Account(id = salesForceID);
debug2 = 'Account ID: ' + acc.id;
Debug Output
salesForceID: 001Q000000OognA
Account ID: 001Q000000OognAIAR
Comments
I apologise for the brevity of the code given, this is for security reasons. I am basically trying to set the ID of the acc before I insert/upsert/update it. I appreciate any explanations for why it could be appending "IAR" and or any alternate ways to update a record given an input AccountId. I do understand that if you pass the id in as a URL variable that SalesForce will automatically do this for you. However, I am passing more than one variable to the page as there are three separate use cases.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
001Q000000OognA 是“标准”15 个字符的 Salesforce ID。 15 个字符的 ID 区分大小写。
001Q000000OognAIAR 是该 ID 的不区分大小写的 18 个字符版本。
任何一个都可以。您无需担心差异。如果由于某种原因您确实需要在参数等中使用 15 个字符的版本,您可以安全地截断最后 3 位数字。
更多信息请参见:http://www.salesforce.com/us /developer/docs/api/Content/field_types.htm
001Q000000OognA is the "standard" 15-character Salesforce ID. 15-character ID's are case-sensitive.
001Q000000OognAIAR is the case-insensitive 18-character version of that ID.
Either one is fine. You do not need to worry about the difference. If for some reason you really need to use the 15-character version in parameters etc, you can safely truncate the last 3 digits.
More information here: http://www.salesforce.com/us/developer/docs/api/Content/field_types.htm