0

我正在尝试在单击按钮时创建一个名为 Guarantor__c 的对象的多个记录,该对象是 Opportunity 和 Contact 的子对象。所有担保人记录都应与按钮所在页面上的机会相关。记录是具有担保人记录类型的商机客户的所有联系人。下面的 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); 
    } 
}
4

1 回答 1

0
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);
于 2014-02-03T21:23:12.127 回答