从执行jscript列表按钮创建多个相关对象
Creating multiple related objects from execute jscript list button
我正在尝试通过单击按钮创建名为Guarantor__c的对象(商机和联系人的子项)的多个记录。 所有担保人记录都应与按钮所在页面上的商机相关。 这些记录是具有担保人记录类型的商机帐户的所有联系人。 下面的 SOQL 非常简单。 这将运行而不会出错,但不输入任何记录。 有什么想法吗?
{!REQUIRESCRIPT('/soap/ajax/27.0/connection.js')}
var url = parent.location.href;
var updateRecords = [];
var principalContacts = sforce.connection.query("Select Id From Contact where AccountId ='{!Account.Id}' and RecordTypeId ='012A0000000nr4BIAQ'");
var principalContactsArray = principalContacts.getArray("records");
if (principalContactsArray.length < 1){
alert("There are no guarantors for this opportunity. Go back to the Account and enter the guarantors.")
}else{
for (eachPrincipalContact in principalContactsArray){
var newGuarantor = new sforce.SObject("Guarantor__c");
newGuarantor.COntact__ = eachPrincipalContact;
newGuarantor.Opportunity__c ="{!Opportunity.Id}";
updateRecords.push(newGuarantor);
sforce.connection.create(updateRecords);
}
}
sforce.connection.create(updateRecords);
应该放在 for 循环之外。
for (eachPrincipalContact in principalContactsArray){
var newGuarantor = new sforce.SObject("Guarantor__c");
newGuarantor.COntact__ = eachPrincipalContact;
newGuarantor.Opportunity__c ="{!Opportunity.Id}";
updateRecords.push(newGuarantor);
}
sforce.connection.create(updateRecords);
相关文章:
- JavaScript名称空间和对象创建
- 从不同的对象创建阵列
- Nodejs-从对象创建可读流
- Javascript对象创建实践
- 插件SDK中的动态或计算对象创建
- 为json对象创建一个动态表
- 对象.创建解释
- 从对象创建嵌套数组失败
- 从JSON对象创建具有超链接的HTML表
- 如何将文档对象创建为HTML页面
- 创建一个类,该类使用es6类语法将Function对象创建为实例
- KineticJS在对象创建(NOOB)后更改属性
- 对象创建中的JavaScript && notation
- Javascript对象创建-创建许多对象
- 从另一个JSON对象创建JSON对象
- 使用linq.js从多个对象创建JSON对象数组
- 如何使用Immutable.js从javascript原始对象创建记录映射
- 在fabric.js中初始化对象创建的子类
- Angularfire:从$FirebaseObject的子对象创建$FirebaseObject
- 为JSON对象创建CRUD