![enter image description here][1]



I've been having this problem for some time now.  Right now this trigger is sitting on prod, and has recently broke I have tried to rewrite the trigger, re write the test class but I can't figure out how to fix it.  What else should I be looking at/taking into consideration with this trigger.  

After doing some research about this topic I found a bunch of posts but none of them help.  Such as adding isActive = true.  The following is my trigger, which I think my logic will work.  Could someone give me some guidance on how to properly test this?


I asked this question recently located [here][2], and I was told I can't do it this way but it is all working up to 

    if(groupMap.containsKey(ld.CreatedById))

After this point it doesn't get into my condition, which is why I need help with my test class. 

So in the end
Is this possible?

Should I be looking at something else besides the trigger.

Trigger

	trigger PartnerLeadShare on Lead (after insert,after update) {

	if(Trigger.isAfter){
	List<LeadShare> leadShareList = new list<LeadShare>();   
		Set<id>pUserMap=new set<id>();  
		  for(User u: [select id,UserType,isActive from user where UserType = 'PowerPartner' and IsActive = True]){       
				   {
					pUserMap.add(u.id);  
					System.debug('pUserMap ' +pUserMap);
			}
		  }
	  Map<Id, GroupMember> groupMap = new Map <Id, GroupMember>();
	for(GroupMember grp : [select GroupId, UserOrGroupId from GroupMember where UserORGroupID IN:pUserMap]){
		groupMap.put(grp.UserOrGroupId, grp);
		}
	System.debug('groupList    '+groupMap ); 
	if(pUserMap != null){
		//System.debug('Inside PartUserMap != null');
		for(Lead ld: trigger.new){  
			System.debug('Created BY!!  ' +ld.CreatedById);  
			 if(groupMap.containsKey(ld.CreatedById)){    
					System.debug('Inside GroupMap Contains');          
					LeadShare ldShare = new LeadShare (LeadId = ld.id, LeadAccessLevel = 'Edit');   
					leadShareList.add(ldShare ); 
				}       
		} 
	} 

Test Class

     static testMethod void myUnitTest1() {     
  	
  	Profile p = [SELECT Id FROM Profile WHERE Name='Disti Partner'];  

    List<Lead> leadList = new List<Lead>();
    List<LeadShare> leadShareList = new list<LeadShare>(); 	
	
    for(integer i =0; i<3; i++){ 
    Lead ld = new Lead();
    ld.lastName = 'Tester';  
    ld.Company = 'Debbie TestRep';
    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';
    system.debug('ls ++!@+!  '  +ls); 
    insert ls;


  [1]: https://i.sstatic.net/voH27.png
  [2]: http://salesforce.stackexchange.com/questions/33638/creating-lead-shares?noredirect=1#comment47300_33638