I'm getting an error INACTIVE_OWNER_OR_USER, operation performed with inactive user, and I have been doing a lot of research and the cause that I have found for this is its attempting to assign a my lead to inactive user. So I understand that part I think the issue is now I don't actually know how to fix it, I didn't write this trigger/test class and I'm not sure how to go forward.
Do I need to create a new Test User? I've never worked on the Lead object before..
Edit** I added IsActive = True the trigger user query, no luck.
Edit** I just went talking to anyone that might have an idea about UserTypes, and they have no idea what UserType = 'PowerPartner' is. So I changed it to a different UserType.. didn't work
Edit** I'm nuking this trigger, I have to re write it..
Test Class
@isTest
private class PartnerLeadShare_test {
static testMethod void myUnitTest1() {
List<Lead> leadList = new List<Lead>();
List<LeadShare> leadShareList = new list<LeadShare>();
Lead ld = new Lead();
ld.lastName = 'Tester';//=/
ld.Company = 'MyCompany';
ld.Status = 'Open';
ld.Program_EAU__c ='11';
insert ld;
system.debug('ld****' +ld);
GroupMember groupMemberStore = [select GroupId,UserOrGroupId from GroupMember limit 1];
LeadShare ls = new LeadShare();
ls.LeadId = ld.id;
ls.UserOrGroupId = groupMemberStore.UserOrGroupId ;
ls.LeadAccessLevel = 'Edit';
leadShareList.add(ls);
if(leadShareList.size()>0){
system.debug('INSIDE LEADSHARE LIST.');
insert leadShareList;
}
}
}
Don't know this will help but here is my trigger..
trigger PartnerLeadShare on Lead (after insert,after update) {
Map<id,User>PartnerUsermap = new Map<id,user>([select id,UserType from user where UserType = 'PowerPartner' and IsActive = True] );
List<GroupMember>GroupMemberList = new List<GroupMember>([select GroupId,UserOrGroupId from GroupMember]);
System.debug('PartnerUsermap === ' +PartnerUsermap);
System.debug('GroupMemberList '+GroupMemberList );
List<LeadShare> leadShareList = new list<LeadShare>();
if(!PartnerUsermap.isEmpty()){
for(Lead ld: trigger.new){
for(GroupMember grpmem : GroupMemberList){
if(grpmem.UserOrGroupId == ld.CreatedById){
LeadShare ldShare = new LeadShare (LeadId = ld.id,UserOrGroupId = grpmem.GroupId,LeadAccessLevel = 'Edit');
leadShareList.add(ldShare );
}
}
}
}
if(!leadShareList.isEmpty()){
Database.SaveResult[] lsr = Database.insert(leadShareList,false);
Integer i=0;
for(Database.SaveResult sr : lsr){
if(!sr.isSuccess()){
Database.Error err = sr.getErrors()[0];
if(!(err.getStatusCode() == StatusCode.FIELD_FILTER_VALIDATION_EXCEPTION
&& err.getMessage().contains('AccessLevel'))){
trigger.newMap.get(leadShareList[i].LeadId).
addError(
'Unable to grant sharing access due to following exception: '
+ err.getMessage());
}
}
i++;
}
}