我工作的解决方案张贴在这里:http://mysalesforcecode.blogspot.com/2012/09/how-to-copy-record-owner-from-cloning.html失败的测试类
就像希望的按钮和触发的工作,但我不断收到测试失败归因于第二系统在我的测试(测试如果断言机会主人是按照原来的主人场保留我的顶点新手,所以我可以做一些显然是错误的......希望如此 - 由于
按钮:!
{!URLFOR($Action.Opportunity.Clone,Opportunity.Id,
[cloneli=1,opp11='Prospecting',opp12='10',opp9=
TEXT(MONTH(Opportunity.CloseDate))+"/"
+TEXT(DAY(Opportunity.CloseDate))+"/"
+TEXT(YEAR(Opportunity.CloseDate)+1)
])}&00NZ0000000kfYf={!Opportunity.OwnerId}&retURL={!Opportunity.Id}
触发(每更新回答如下):
trigger OwnerIdChange on Opportunity (before insert)
{
for(Opportunity o : Trigger.new)
{
if(o.OriginalOwner__c != null)
o.OwnerId = o.OriginalOwner__c;
}
}
测试类:
@istest
private class Opportunities_Test {
static testMethod void Opportunities_Test1() {
test.starttest();
Profile p = [SELECT Id FROM Profile WHERE Name='Standard User'];
User u = new User(Alias = 'standt', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = p.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
insert u;
Profile s = [SELECT Id FROM Profile WHERE Name='System Administrator'];
User u2 = new User(Alias = 'admin', Email='[email protected]',
EmailEncodingKey='UTF-8', LastName='Testing2', LanguageLocaleKey='en_US',
LocaleSidKey='en_US', ProfileId = s.Id,
TimeZoneSidKey='America/Los_Angeles', UserName='[email protected]');
insert u2;
Account a = new account(Name = 'Test1');
insert a;
List <Opportunity> Opportunity;
Opportunity O1 = new Opportunity();
O1.ownerid = u.id;
O1.accountid = a.id;
O1.Amount= 1;
O1.CloseDate = Date.today();
O1.Name = 'Testing';
O1.StageName= 'Prospecting';
insert O1;
Account b = new account(Name = 'Test2');
insert b;
List <Opportunity> Opportunity2;
Opportunity O2 = new Opportunity();
O2.accountid = b.id;
O2.ownerid = u.id;
O2.Amount= 1;
O2.CloseDate = Date.today();
O2.Name = 'Testing2';
O2.StageName= 'Prospecting';
O2.OriginalOwner__c= u2.id;
insert O2;
List<Opportunity> z = [SELECT Id, Ownerid, Name FROM Opportunity WHERE id= :O2.id];
system.assertEquals(O1.ownerid, u.id);
system.assertEquals(O2.OwnerID, u2.id);
test.stoptest();
}
}
我编辑了当前的代码。有趣的是,尽管测试类最终因第二个系统断言而失败,但触发器说它具有100%的覆盖率。当然,我可以通过删除断言来让测试类通过,但我确实想要这样做。 – user2120892 2013-03-06 17:09:47
截至今天,仍然没有最终的解决方案......请参阅我在3月6日18:13最后的评论(下方) - 该过程在沙箱中正常工作(保持原始机会所有者使用按钮时)。我只是无法通过测试课程。 – user2120892 2013-03-12 19:59:36