我工作的解決方案張貼在這裏: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