我正在为我的触发器编写一个测试类,用于检查帐户重复项。 但我得到以下错误在我的测试类:触发器测试类
Error: Compile Error: Comparison arguments must be compatible types: Schema.SObjectField, String at line 35 column 42
测试类是:
@isTest
public class trg_AccountDuplicatePreventer_FinalTest{
static testMethod void Test0_TestInsertWithValue()
{
//Set<Account> Accset = new Set<Account>();
Account acc1 = new Account(Name = 'Agency0', Phone='9811309977',Physical_Street__c = 'ABC0', Physical_State_Province__c = 'NY',Physical_Zip_Postal_Code__c = '2010',Physical_Country__c= 'USA');
Account acc2 = new Account(Name = 'Agency00', Phone='9811309988',Physical_Street__c = 'ABC00', Physical_State_Province__c = 'NY',Physical_Zip_Postal_Code__c = '2010',Physical_Country__c= 'USA');
Account acc3 = new Account(Name = 'Agency000', Phone='9811309999',Physical_Street__c = 'ABC000', Physical_State_Province__c = 'NY',Physical_Zip_Postal_Code__c = '2010',Physical_Country__c= 'USA');
Account[] accs = new Account[]{acc1,acc2,acc3};
insert accs;
acc2.Phone='9811309999';
acc3.Physical_Street__c='ABC0000';
acc3.Phone='9811308888';
update accs;
Account dupe1 = new Account(Name = 'Agency0', Phone='9811309977',Physical_Street__c = 'ABC0', Physical_State_Province__c = 'NY',Physical_Zip_Postal_Code__c = '2010',Physical_Country__c= 'USA');
try{
insert dupe1;
System.assert(false);
}catch(DMLException e)
{
for (Integer i = 0; i < e.getNumDml(); i++)
{
System.assert(e.getNumDml() == 1);
System.assert(e.getDmlIndex(i) == 0);
System.assert(e.getDmlFields(i).size() == 3);
System.assert(e.getDmlFields(i)[0] == 'Name');
System.assert(e.getDmlFields(i)[1] == 'Phone');
System.assert(e.getDmlFields(i)[2] == 'Physical_Street__c');
System.assert(e.getDmlMessage(i).indexOf('An account with this name, phone, street already exists.') > -1);
}
}
}
}
如何在我的测试代码修复这个错误?
谢谢!
您可能想要指定更多细节,例如您要在此处实现的内容。另外,你能突出显示它失败的地方吗? – Anup 2012-07-28 23:29:59
嗨,Anup,我的触发器代码尝试根据帐户名称,街道和手机匹配或名称和手机匹配或名称和街道匹配来识别系统中的帐户重复。我写的测试类给了我100%的覆盖率,但是我得到1个测试失败: – user1518186 2012-07-29 08:05:20
消息:System.DmlException:插入失败。第0行的第一个例外;第一个错误:FIELD_CUSTOM_VALIDATION_EXCEPTION,
具有此名称/电话/物理街道的代理记录存在于系统中。如果您希望创建代理记录,请将“创建新记录”的字段值更改为YES。
潜在重复机构包括:
名称,电话和实体街匹配的代理商:Agency000 |
与名称和电话匹配的代理商:Agency000 – user1518186 2012-07-29 08:12:34