逻辑:
public static void wmgRemoveOldGroupQueue(Map<Id,Case> newMap, Map<Id,Case> oldMap){
String wmgRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('WMG_Operations_Workflow').getRecordTypeId();
for (Case o : newMap.values()) {
system.debug('o.OwnerId == '+o.OwnerId+' oldMap.get(o.Id).OwnerId =='+oldMap.get(o.Id).OwnerId);
system.debug('o.RecordTypeId '+o.RecordTypeId+ 'wmgRecordTypeId'+wmgRecordTypeId);
if (o.RecordTypeId == wmgRecordTypeId && !((String)o.OwnerId).startsWith('005') &&
(o.OwnerId != oldMap.get(o.Id).OwnerId)) {
o.ANN_Accepted_From_Queue__c = '';
}
system.debug('o.ANN_Accepted_From_Queue__c' +o.ANN_Accepted_From_Queue__c);
}
}
测试类:
static testMethod void wmgRemoveOldQueueTest() {
//setup
User thisUser = [SELECT Id FROM User WHERE Id = :UserInfo.getUserId()];
String wmgRecordTypeId = Schema.SObjectType.Case.getRecordTypeInfosByDeveloperName().get('WMG_Operations_Workflow').getRecordTypeId();
String assertMsg = 'Accepted From Queue could not clear out';
//QueueSobject q = [SELECT QueueId, Queue.Name FROM QueueSobject WHERE SObjectType = 'Case' and Queue.Name = 'WMG Ops - Licensing' LIMIT 1];
Case c = new Case();
c.OwnerId = thisUser.Id;
c.RecordTypeId = wmgRecordTypeId;
c.ANN_Accepted_From_Queue__c = 'Test';
insert c;
System.debug('Owner id at insert is '+c.OwnerId);
Group testGroup = new Group(Name='test group', Type='Queue');
insert testGroup;
System.runAs(new User(Id=UserInfo.getUserId()))
{
QueuesObject q = new QueueSObject(QueueID = testGroup.id, SObjectType = 'Case');
insert q;
}
//c = [SELECT OwnerId, ANN_Accepted_From_Queue__c, RecordTypeId FROM Case WHERE Id = :c.Id];
//c.OwnerId = thisUser.Id;
//update c;
//System.assertEquals(Test, [SELECT ANN_Accepted_From_Queue__c FROM Case WHERE Id = :c.Id].ANN_Accepted_From_Queue__c, 'Failed');
system.assertEquals(c.OwnerId, thisUser.Id, 'Failed2');
//c.RecordTypeId = wmgRecordTypeId;
//system.assert(((String)c.OwnerId).startsWith('00G'), 'Owner issue');
//system.assert(((String)c.OwnerId).startsWith('00G'), 'Owner issue');
case newCase = [SELECT id, Ownerid, ANN_Accepted_From_Queue__c FROM Case WHERE Id = :c.Id];
newCase.OwnerId=testGroup.Id;
//QueueSobject q1 = [SELECT QueueId, Queue.Name FROM QueueSobject WHERE SObjectType = 'Case' and QueueID=testGroup.Id LIMIT 1];
Test.startTest();
update newCase;
Test.stopTest();
system.debug('newCase.OwnerId1 =='+newCase.OwnerId);
case r = [SELECT id, Ownerid, ANN_Accepted_From_Queue__c FROM Case WHERE Id = :newCase.Id];
system.debug('r Owner Id =='+r.OwnerId);
System.assertEquals('',[SELECT ANN_Accepted_From_Queue__c FROM Case Where Id=:r.Id].ANN_Accepted_From_Queue__c, assertMsg);
}
在这一步失败: System.assertEquals('',[SELECT ANN_Accepted_From_Queue__c FROM Case Where Id=:r.Id].ANN_Accepted_From_Queue__c, assertMsg);
在这一步: system.debug('o.RecordTypeId '+o.RecordTypeId+ 'wmgRecordTypeId'+wmgRecordTypeId);
18:14:23:180 USER_DEBUG [720]|DEBUG|o.OwnerId == 00518000003xRhcAAE oldMap.get(o.Id).OwnerId ==00518000003xRhcAAE 无法找到问题所在: